#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
int n,k;
int l[100005];
int r[100005];
ii a[100005];
set<ii> s;
vector<int> ans;
int p[17][100005];
int st[17][100005];
int cur = 0;
int MX(int l, int r){
if (l == r) return st[0][l];
int d = 31-__builtin_clz(r-l+1);
return max(st[d][l], st[d][r-(1<<d)+1]);
}
int find(int x){
int lo = 1, hi = n+1;
while (lo < hi){
int mid = (lo+hi)/2;
if (MX(1, mid) >= x){
hi = mid;
}
else lo = mid+1;
}
return lo;
}
int query(int l, int r){
int x = find(l);
int ret = 0;
for (int i = 16; i >= 0; i--){
if (p[i][x] && a[p[i][x]].se <= r){
x = p[i][x];
ret += (1<<i);
}
}
///printf("querying %d %d --> %d\n",l,r, ret);
return ret;
}
bool add(int l, int r){
auto it = s.lower_bound({r, -1});
assert(it != s.begin());
auto LL = prev(it);
auto RR = it;
if (LL->se > l) return false;
int L = LL->se;
int R = RR->fi;
int nw = cur - query(L, R) + query(L, l) + query(r, R) + 1;
if (nw >= k){
cur = nw;
return true;
}
else return false;
}
int main(){
scanf("%d%d",&n,&k);
for (int i = 1; i <= n; i++){
scanf("%d%d",&l[i], &r[i]);
a[i] = {l[i], r[i]};
}
sort(a+1, a+n+1, [](ii a, ii b){
return a.se < b.se;
});
a[0] = {0,0};
a[n+1] = {1000000001,1000000001};
for (int i = 1; i <= n; i++){
st[0][i] = a[i].fi;
}
for (int k = 1; k < 17; k++){
for (int i = 0; i <= n+1; i++){
if (i + (1<<(k-1)) <= n+1){
st[k][i] = max(st[k-1][i], st[k-1][i+(1<<(k-1))]);
}
}
}
for (int i = 1; i <= n; i++){
p[0][i] = find(a[i].se);
}
for (int k = 1; k < 17; k++){
for (int i = 1; i <= n; i++){
if (p[k-1][i]) p[k][i] = p[k-1][p[k-1][i]];
}
}
s.insert({0,0});
s.insert({1000000001,1000000001});
cur = query(0, 1000000001);
if (cur < k){
printf("-1\n");
return 0;
}
for (int i = 1; i <= n; i++){
if (add(l[i], r[i])){
ans.push_back(i);
s.insert({l[i], r[i]});
}
}
for (int i = 0; i < k; i++) printf("%d\n",ans[i]);
}
Compilation message
event2.cpp: In function 'int main()':
event2.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
event2.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | scanf("%d%d",&l[i], &r[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
109 ms |
19884 KB |
Output is correct |
5 |
Correct |
139 ms |
21828 KB |
Output is correct |
6 |
Correct |
107 ms |
21828 KB |
Output is correct |
7 |
Correct |
106 ms |
21700 KB |
Output is correct |
8 |
Correct |
109 ms |
21848 KB |
Output is correct |
9 |
Correct |
113 ms |
21824 KB |
Output is correct |
10 |
Correct |
115 ms |
21800 KB |
Output is correct |
11 |
Correct |
112 ms |
21796 KB |
Output is correct |
12 |
Correct |
87 ms |
19676 KB |
Output is correct |
13 |
Correct |
88 ms |
19588 KB |
Output is correct |
14 |
Correct |
88 ms |
19640 KB |
Output is correct |
15 |
Correct |
86 ms |
19528 KB |
Output is correct |
16 |
Correct |
62 ms |
16236 KB |
Output is correct |
17 |
Correct |
52 ms |
16224 KB |
Output is correct |
18 |
Correct |
71 ms |
16264 KB |
Output is correct |
19 |
Correct |
46 ms |
14520 KB |
Output is correct |
20 |
Correct |
42 ms |
14464 KB |
Output is correct |
21 |
Correct |
42 ms |
14548 KB |
Output is correct |
22 |
Correct |
53 ms |
13212 KB |
Output is correct |
23 |
Correct |
43 ms |
13224 KB |
Output is correct |
24 |
Correct |
41 ms |
13260 KB |
Output is correct |
25 |
Correct |
40 ms |
11956 KB |
Output is correct |
26 |
Correct |
51 ms |
11944 KB |
Output is correct |
27 |
Correct |
40 ms |
11964 KB |
Output is correct |
28 |
Correct |
38 ms |
16576 KB |
Output is correct |
29 |
Correct |
43 ms |
16396 KB |
Output is correct |
30 |
Correct |
42 ms |
15520 KB |
Output is correct |
31 |
Correct |
39 ms |
14412 KB |
Output is correct |
32 |
Correct |
45 ms |
13128 KB |
Output is correct |
33 |
Correct |
37 ms |
11892 KB |
Output is correct |
34 |
Correct |
88 ms |
19492 KB |
Output is correct |
35 |
Correct |
82 ms |
19488 KB |
Output is correct |
36 |
Correct |
81 ms |
19284 KB |
Output is correct |
37 |
Correct |
82 ms |
19164 KB |
Output is correct |
38 |
Correct |
77 ms |
19192 KB |
Output is correct |
39 |
Correct |
78 ms |
19148 KB |
Output is correct |
40 |
Correct |
82 ms |
19152 KB |
Output is correct |
41 |
Correct |
85 ms |
19128 KB |
Output is correct |
42 |
Correct |
44 ms |
16324 KB |
Output is correct |
43 |
Correct |
81 ms |
19028 KB |
Output is correct |
44 |
Correct |
79 ms |
18920 KB |
Output is correct |
45 |
Correct |
76 ms |
18844 KB |
Output is correct |
46 |
Correct |
78 ms |
18688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
109 ms |
19884 KB |
Output is correct |
5 |
Correct |
139 ms |
21828 KB |
Output is correct |
6 |
Correct |
107 ms |
21828 KB |
Output is correct |
7 |
Correct |
106 ms |
21700 KB |
Output is correct |
8 |
Correct |
109 ms |
21848 KB |
Output is correct |
9 |
Correct |
113 ms |
21824 KB |
Output is correct |
10 |
Correct |
115 ms |
21800 KB |
Output is correct |
11 |
Correct |
112 ms |
21796 KB |
Output is correct |
12 |
Correct |
87 ms |
19676 KB |
Output is correct |
13 |
Correct |
88 ms |
19588 KB |
Output is correct |
14 |
Correct |
88 ms |
19640 KB |
Output is correct |
15 |
Correct |
86 ms |
19528 KB |
Output is correct |
16 |
Correct |
62 ms |
16236 KB |
Output is correct |
17 |
Correct |
52 ms |
16224 KB |
Output is correct |
18 |
Correct |
71 ms |
16264 KB |
Output is correct |
19 |
Correct |
46 ms |
14520 KB |
Output is correct |
20 |
Correct |
42 ms |
14464 KB |
Output is correct |
21 |
Correct |
42 ms |
14548 KB |
Output is correct |
22 |
Correct |
53 ms |
13212 KB |
Output is correct |
23 |
Correct |
43 ms |
13224 KB |
Output is correct |
24 |
Correct |
41 ms |
13260 KB |
Output is correct |
25 |
Correct |
40 ms |
11956 KB |
Output is correct |
26 |
Correct |
51 ms |
11944 KB |
Output is correct |
27 |
Correct |
40 ms |
11964 KB |
Output is correct |
28 |
Correct |
38 ms |
16576 KB |
Output is correct |
29 |
Correct |
43 ms |
16396 KB |
Output is correct |
30 |
Correct |
42 ms |
15520 KB |
Output is correct |
31 |
Correct |
39 ms |
14412 KB |
Output is correct |
32 |
Correct |
45 ms |
13128 KB |
Output is correct |
33 |
Correct |
37 ms |
11892 KB |
Output is correct |
34 |
Correct |
88 ms |
19492 KB |
Output is correct |
35 |
Correct |
82 ms |
19488 KB |
Output is correct |
36 |
Correct |
81 ms |
19284 KB |
Output is correct |
37 |
Correct |
82 ms |
19164 KB |
Output is correct |
38 |
Correct |
77 ms |
19192 KB |
Output is correct |
39 |
Correct |
78 ms |
19148 KB |
Output is correct |
40 |
Correct |
82 ms |
19152 KB |
Output is correct |
41 |
Correct |
85 ms |
19128 KB |
Output is correct |
42 |
Correct |
44 ms |
16324 KB |
Output is correct |
43 |
Correct |
81 ms |
19028 KB |
Output is correct |
44 |
Correct |
79 ms |
18920 KB |
Output is correct |
45 |
Correct |
76 ms |
18844 KB |
Output is correct |
46 |
Correct |
78 ms |
18688 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |