#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct segTree{
int tree[800002], lazy[800002];
void propagate(int i, int l, int r){
tree[i] += lazy[i];
if(l != r){
lazy[i*2] += lazy[i];
lazy[i*2+1] += lazy[i];
}
lazy[i] = 0;
}
void update(int i, int l, int r, int s, int e, int val){
propagate(i, l, r);
if(r<s || e<l) return;
if(s<=l && r<=e){
lazy[i] += val;
propagate(i, l, r);
return;
}
int m = (l+r)>>1;
update(i*2, l, m, s, e, val);
update(i*2+1, m+1, r, s, e, val);
tree[i] = min(tree[i*2], tree[i*2+1]);
}
int getRange(int i, int l, int r, int s, int e){
propagate(i, l, r);
if(r<s || e<l) return 1e9;
if(s<=l && r<=e) return tree[i];
int m = (l+r)>>1;
return min(getRange(i*2, l, m, s, e), getRange(i*2+1, m+1, r, s, e));
}
} tree;
int n, m;
int par[200002];
int parSuffix[200002];
int main(){
scanf("%d %d", &n, &m);
for(int i=1; i<=n; i++) par[i] = i;
for(int i=1; i<=m; i++){
int x, y;
scanf("%d %d", &x, &y);
if(x>y) swap(x, y);
par[y] = min(par[y], x);
}
parSuffix[n+1] = 1e9;
for(int i=n; i>=1; i--){
parSuffix[i] = min(parSuffix[i+1], par[i]);
}
for(int i=2; i<=n; i++){
tree.update(1, 1, n, 1, min(i-1, par[i]-1), 1);
int tmp = tree.getRange(1, 1, n, 1, min(i-1, parSuffix[i+1]-1));
tree.update(1, 1, n, i, i, tmp);
}
printf("%d", tree.getRange(1, 1, n, n, n));
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
252 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
252 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
252 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
4 ms |
460 KB |
Output is correct |
24 |
Correct |
4 ms |
460 KB |
Output is correct |
25 |
Correct |
7 ms |
432 KB |
Output is correct |
26 |
Correct |
7 ms |
460 KB |
Output is correct |
27 |
Correct |
7 ms |
460 KB |
Output is correct |
28 |
Correct |
7 ms |
444 KB |
Output is correct |
29 |
Correct |
4 ms |
460 KB |
Output is correct |
30 |
Correct |
11 ms |
452 KB |
Output is correct |
31 |
Correct |
11 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
252 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
252 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
4 ms |
460 KB |
Output is correct |
24 |
Correct |
4 ms |
460 KB |
Output is correct |
25 |
Correct |
7 ms |
432 KB |
Output is correct |
26 |
Correct |
7 ms |
460 KB |
Output is correct |
27 |
Correct |
7 ms |
460 KB |
Output is correct |
28 |
Correct |
7 ms |
444 KB |
Output is correct |
29 |
Correct |
4 ms |
460 KB |
Output is correct |
30 |
Correct |
11 ms |
452 KB |
Output is correct |
31 |
Correct |
11 ms |
460 KB |
Output is correct |
32 |
Correct |
174 ms |
5900 KB |
Output is correct |
33 |
Correct |
188 ms |
5928 KB |
Output is correct |
34 |
Correct |
178 ms |
5572 KB |
Output is correct |
35 |
Correct |
228 ms |
5920 KB |
Output is correct |
36 |
Correct |
218 ms |
5936 KB |
Output is correct |
37 |
Correct |
220 ms |
5924 KB |
Output is correct |
38 |
Correct |
175 ms |
5992 KB |
Output is correct |
39 |
Correct |
183 ms |
5912 KB |
Output is correct |
40 |
Correct |
100 ms |
3112 KB |
Output is correct |
41 |
Correct |
185 ms |
5544 KB |
Output is correct |
42 |
Correct |
233 ms |
5940 KB |
Output is correct |
43 |
Correct |
229 ms |
5940 KB |
Output is correct |
44 |
Correct |
1 ms |
204 KB |
Output is correct |
45 |
Correct |
1 ms |
204 KB |
Output is correct |