제출 #896762

#제출 시각아이디문제언어결과실행 시간메모리
896762juliany2Event Hopping 2 (JOI21_event2)C++17
100 / 100
131 ms27084 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() const int N = 2e5 + 7, L = 20; int n, k; array<int, 2> a[N]; int lift[N][L]; int main() { cin.tie(0)->sync_with_stdio(false); cin >> n >> k; vector<int> srt = {0}; for (int i = 1; i <= n; i++) { cin >> a[i][0] >> a[i][1]; srt.push_back(a[i][0]); srt.push_back(a[i][1]); } sort(all(srt)); srt.erase(unique(all(srt)), srt.end()); int m = srt.size(); for (int i = 1; i <= m; i++) lift[i][0] = m + 1; fill(lift[m + 1], lift[m + 1] + L, m + 1); for (int i = 1; i <= n; i++) { a[i][0] = lower_bound(all(srt), a[i][0]) - srt.begin(); a[i][1] = lower_bound(all(srt), a[i][1]) - srt.begin(); lift[a[i][0]][0] = min(lift[a[i][0]][0], a[i][1]); } for (int i = m - 1; i >= 0; i--) { lift[i][0] = min(lift[i][0], lift[i + 1][0]); for (int j = 1; j < L; j++) lift[i][j] = lift[lift[i][j - 1]][j - 1]; } auto query = [&](int l, int r) { int ret = 0; for (int i = L - 1; i >= 0; i--) if (lift[l][i] <= r) l = lift[l][i], ret += (1 << i); return ret; }; int cnt = query(1, m); vector<int> ans; set<int> cov = {0, m}; for (int i = 1; i <= n; i++) { if (*cov.lower_bound(a[i][0]) < a[i][1] || ans.size() == k) continue; int l = *prev(cov.lower_bound(a[i][0])) + 1, r = *cov.lower_bound(a[i][1]); int cur = cnt - query(l, r) + query(l, a[i][0]) + query(a[i][1], r); if (cur + ans.size() + 1 >= k) { ans.push_back(i); cnt = cur; for (int j = a[i][0]; j < a[i][1]; j++) cov.insert(j); } } if (ans.size() < k) cout << -1 << '\n'; else { for (int i : ans) cout << i << '\n'; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

event2.cpp: In function 'int main()':
event2.cpp:57:63: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |         if (*cov.lower_bound(a[i][0]) < a[i][1] || ans.size() == k)
      |                                                    ~~~~~~~~~~~^~~~
event2.cpp:62:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   62 |         if (cur + ans.size() + 1 >= k) {
      |             ~~~~~~~~~~~~~~~~~~~~~^~~~
event2.cpp:70:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   70 |     if (ans.size() < k)
      |         ~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...