#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;
#define X first
#define Y second
#define eb emplace_back
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
template<typename T>
ostream& operator << (ostream &os, vector<T> vec) {
for (int i = 0; i < vec.size(); ++i) {
if (i) os << "\n";
os << vec[i];
}
return os;
}
const int maxn = 2E5 + 5;
#define BUILD_BUG_ON_ZERO(e) void __(){return int : !!(e);}
int n, k;
vector<int> allVal, used(maxn, 0), pre(maxn);
vector<pii> ev, perm;
int countAnswer() {
int r_bound = 0, res = 0;
for (int i = 0; i < n; ++i) {
int id = perm[i].Y;
if (pre[ev[id].Y] - pre[ev[id].X] or ev[id].X < r_bound) continue;
++res, r_bound = ev[id].Y;
}
return res;
}
void solve() {
cin >> n >> k, ev.resize(n), perm.resize(n);
/// discretization ///
for (auto &[l, r] : ev) cin >> l >> r, allVal.eb(l), allVal.eb(r);
sort(ALL(allVal));
allVal.resize(unique(ALL(allVal)) - begin(allVal));
for (auto &[l, r] : ev) {
l = lower_bound(ALL(allVal), l) - begin(allVal);
r = lower_bound(ALL(allVal), r) - begin(allVal);
}
for (int i = 0; i < n; ++i) perm[i] = {ev[i].Y, i};
sort(ALL(perm));
// for (auto [l, r] : ev) cout << l << " " << r << "\n";
if (countAnswer() < k) return cout << -1 << "\n", void();
vector<int> ans;
for (int i = 0; i < n; ++i) {
if (pre[ev[i].Y] - pre[ev[i].X]) continue;
for (int j = ev[i].X+1; j <= ev[i].Y; ++j) ++used[j];
partial_sum(ALL(used), begin(pre));
if (countAnswer() + ans.size() + 1 >= k) {ans.eb(i+1); continue;}
for (int j = ev[i].X+1; j <= ev[i].Y; ++j) --used[j];
partial_sum(ALL(used), begin(pre));
}
ans.resize(k);
cout << ans << "\n";
}
int32_t main() {
fastIO();
int t = 1; // cin >> t;
while (t--) solve();
return 0;
}
Compilation message
event2.cpp: In function 'void solve()':
event2.cpp:69:44: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
69 | if (countAnswer() + ans.size() + 1 >= k) {ans.eb(i+1); continue;}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
event2.cpp: In instantiation of 'std::ostream& operator<<(std::ostream&, std::vector<_Tp>) [with T = int; std::ostream = std::basic_ostream<char>]':
event2.cpp:74:13: required from here
event2.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i = 0; i < vec.size(); ++i) {
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1872 KB |
Output is correct |
2 |
Correct |
1 ms |
1872 KB |
Output is correct |
3 |
Correct |
1 ms |
1868 KB |
Output is correct |
4 |
Execution timed out |
3063 ms |
4576 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1868 KB |
Output is correct |
2 |
Correct |
2 ms |
1868 KB |
Output is correct |
3 |
Correct |
1 ms |
1872 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1868 KB |
Output is correct |
6 |
Correct |
2 ms |
1868 KB |
Output is correct |
7 |
Correct |
3 ms |
1776 KB |
Output is correct |
8 |
Correct |
3 ms |
1868 KB |
Output is correct |
9 |
Correct |
2 ms |
1808 KB |
Output is correct |
10 |
Correct |
2 ms |
1868 KB |
Output is correct |
11 |
Correct |
1 ms |
1868 KB |
Output is correct |
12 |
Correct |
2 ms |
1868 KB |
Output is correct |
13 |
Correct |
1 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1868 KB |
Output is correct |
15 |
Correct |
1 ms |
1868 KB |
Output is correct |
16 |
Correct |
3 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1868 KB |
Output is correct |
18 |
Correct |
2 ms |
1868 KB |
Output is correct |
19 |
Correct |
1 ms |
1868 KB |
Output is correct |
20 |
Correct |
1 ms |
1868 KB |
Output is correct |
21 |
Correct |
3 ms |
1868 KB |
Output is correct |
22 |
Correct |
3 ms |
1868 KB |
Output is correct |
23 |
Correct |
3 ms |
1868 KB |
Output is correct |
24 |
Correct |
1 ms |
1868 KB |
Output is correct |
25 |
Correct |
1 ms |
1872 KB |
Output is correct |
26 |
Correct |
3 ms |
1868 KB |
Output is correct |
27 |
Correct |
4 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1868 KB |
Output is correct |
2 |
Correct |
2 ms |
1868 KB |
Output is correct |
3 |
Correct |
1 ms |
1872 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1868 KB |
Output is correct |
6 |
Correct |
2 ms |
1868 KB |
Output is correct |
7 |
Correct |
3 ms |
1776 KB |
Output is correct |
8 |
Correct |
3 ms |
1868 KB |
Output is correct |
9 |
Correct |
2 ms |
1808 KB |
Output is correct |
10 |
Correct |
2 ms |
1868 KB |
Output is correct |
11 |
Correct |
1 ms |
1868 KB |
Output is correct |
12 |
Correct |
2 ms |
1868 KB |
Output is correct |
13 |
Correct |
1 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1868 KB |
Output is correct |
15 |
Correct |
1 ms |
1868 KB |
Output is correct |
16 |
Correct |
3 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1868 KB |
Output is correct |
18 |
Correct |
2 ms |
1868 KB |
Output is correct |
19 |
Correct |
1 ms |
1868 KB |
Output is correct |
20 |
Correct |
1 ms |
1868 KB |
Output is correct |
21 |
Correct |
3 ms |
1868 KB |
Output is correct |
22 |
Correct |
3 ms |
1868 KB |
Output is correct |
23 |
Correct |
3 ms |
1868 KB |
Output is correct |
24 |
Correct |
1 ms |
1868 KB |
Output is correct |
25 |
Correct |
1 ms |
1872 KB |
Output is correct |
26 |
Correct |
3 ms |
1868 KB |
Output is correct |
27 |
Correct |
4 ms |
1868 KB |
Output is correct |
28 |
Correct |
46 ms |
2124 KB |
Output is correct |
29 |
Correct |
44 ms |
1996 KB |
Output is correct |
30 |
Correct |
22 ms |
2072 KB |
Output is correct |
31 |
Correct |
8 ms |
2076 KB |
Output is correct |
32 |
Correct |
5 ms |
1996 KB |
Output is correct |
33 |
Correct |
3 ms |
1996 KB |
Output is correct |
34 |
Correct |
3 ms |
1996 KB |
Output is correct |
35 |
Correct |
345 ms |
2052 KB |
Output is correct |
36 |
Correct |
383 ms |
2044 KB |
Output is correct |
37 |
Correct |
283 ms |
2044 KB |
Output is correct |
38 |
Correct |
3 ms |
1996 KB |
Output is correct |
39 |
Correct |
296 ms |
2064 KB |
Output is correct |
40 |
Correct |
288 ms |
2048 KB |
Output is correct |
41 |
Correct |
300 ms |
2048 KB |
Output is correct |
42 |
Correct |
3 ms |
1996 KB |
Output is correct |
43 |
Correct |
163 ms |
2064 KB |
Output is correct |
44 |
Correct |
120 ms |
1996 KB |
Output is correct |
45 |
Correct |
95 ms |
1996 KB |
Output is correct |
46 |
Correct |
3 ms |
1996 KB |
Output is correct |
47 |
Correct |
114 ms |
1996 KB |
Output is correct |
48 |
Correct |
60 ms |
1996 KB |
Output is correct |
49 |
Correct |
20 ms |
1996 KB |
Output is correct |
50 |
Correct |
3 ms |
1996 KB |
Output is correct |
51 |
Correct |
150 ms |
1996 KB |
Output is correct |
52 |
Correct |
97 ms |
1996 KB |
Output is correct |
53 |
Correct |
14 ms |
1996 KB |
Output is correct |
54 |
Correct |
3 ms |
1996 KB |
Output is correct |
55 |
Correct |
347 ms |
2060 KB |
Output is correct |
56 |
Correct |
343 ms |
2056 KB |
Output is correct |
57 |
Correct |
343 ms |
2116 KB |
Output is correct |
58 |
Correct |
341 ms |
2144 KB |
Output is correct |
59 |
Correct |
344 ms |
2052 KB |
Output is correct |
60 |
Correct |
341 ms |
1996 KB |
Output is correct |
61 |
Correct |
343 ms |
2048 KB |
Output is correct |
62 |
Correct |
347 ms |
2044 KB |
Output is correct |
63 |
Correct |
347 ms |
2068 KB |
Output is correct |
64 |
Correct |
3 ms |
2028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1872 KB |
Output is correct |
2 |
Correct |
1 ms |
1872 KB |
Output is correct |
3 |
Correct |
1 ms |
1868 KB |
Output is correct |
4 |
Execution timed out |
3063 ms |
4576 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |