이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |