#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
int sz(const T &a){return int(a.size());}
const int MN=2e5+1;
int n;
struct seg{
struct node{
int data,lazy;
node(){
data=0,lazy=0;
}
void apply(int a){
data+=a;
lazy+=a;
}
}t[2*MN];
void prop(int ind, int le, int ri){
int mid=(le+ri)/2;
int left=ind+1,right=ind+(mid-le+1)*2;
t[left].apply(t[ind].lazy),t[right].apply(t[ind].lazy);
t[ind].lazy=0;
}
void update(int ind, int le, int ri, int l, int r, int val){
if(l>ri||r<le||l>r)return;
if(le>=l&&ri<=r){
t[ind].apply(val);
return;
}
prop(ind,le,ri);
int mid=(le+ri)/2;
int left=ind+1,right=ind+(mid-le+1)*2;
update(left,le,mid,l,r,val),update(right,mid+1,ri,l,r,val);
t[ind].data=min(t[left].data,t[right].data);
}
int query(int ind, int le, int ri, int l, int r){
if(l>ri||r<le||l>r)return n+1;
if(le>=l&&ri<=r)return t[ind].data;
prop(ind,le,ri);
int mid=(le+ri)/2;
int left=ind+1,right=ind+(mid-le+1)*2;
return min(query(left,le,mid,l,r),query(right,mid+1,ri,l,r));
}
}tree;
int mostright[MN],mostleft[MN];
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int m,a,b;
cin>>n>>m;
for(int i=1;i<=n;i++)mostleft[i]=n+1;
for(int i=0;i<m;i++){
cin>>a>>b;
mostleft[a]=min(mostleft[a],b);
mostleft[b]=min(mostleft[b],a);
mostright[a]=max(mostright[a],b);
mostright[b]=max(mostright[b],a);
}
int ptr=0;
for(int i=2;i<=n;i++){
while(ptr+1<i&&mostright[ptr+1]<=i)ptr++;
tree.update(0,1,n,1,min(i-1,mostleft[i]-1),1);
int te=tree.query(0,1,n,1,ptr);
tree.update(0,1,n,i,i,te);
}
printf("%d\n",tree.query(0,1,n,n,n));
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3404 KB |
Output is correct |
2 |
Correct |
3 ms |
3404 KB |
Output is correct |
3 |
Correct |
3 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
3 ms |
3404 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
3 ms |
3404 KB |
Output is correct |
8 |
Correct |
3 ms |
3404 KB |
Output is correct |
9 |
Correct |
4 ms |
3404 KB |
Output is correct |
10 |
Correct |
3 ms |
3404 KB |
Output is correct |
11 |
Correct |
3 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3404 KB |
Output is correct |
2 |
Correct |
3 ms |
3404 KB |
Output is correct |
3 |
Correct |
3 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
3 ms |
3404 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
3 ms |
3404 KB |
Output is correct |
8 |
Correct |
3 ms |
3404 KB |
Output is correct |
9 |
Correct |
4 ms |
3404 KB |
Output is correct |
10 |
Correct |
3 ms |
3404 KB |
Output is correct |
11 |
Correct |
3 ms |
3456 KB |
Output is correct |
12 |
Correct |
3 ms |
3404 KB |
Output is correct |
13 |
Correct |
3 ms |
3404 KB |
Output is correct |
14 |
Correct |
3 ms |
3404 KB |
Output is correct |
15 |
Correct |
3 ms |
3404 KB |
Output is correct |
16 |
Correct |
3 ms |
3404 KB |
Output is correct |
17 |
Correct |
3 ms |
3404 KB |
Output is correct |
18 |
Correct |
3 ms |
3404 KB |
Output is correct |
19 |
Correct |
3 ms |
3404 KB |
Output is correct |
20 |
Correct |
4 ms |
3404 KB |
Output is correct |
21 |
Correct |
3 ms |
3404 KB |
Output is correct |
22 |
Correct |
3 ms |
3456 KB |
Output is correct |
23 |
Correct |
5 ms |
3404 KB |
Output is correct |
24 |
Correct |
6 ms |
3420 KB |
Output is correct |
25 |
Correct |
10 ms |
3496 KB |
Output is correct |
26 |
Correct |
8 ms |
3404 KB |
Output is correct |
27 |
Correct |
8 ms |
3404 KB |
Output is correct |
28 |
Correct |
10 ms |
3404 KB |
Output is correct |
29 |
Correct |
5 ms |
3404 KB |
Output is correct |
30 |
Correct |
13 ms |
3500 KB |
Output is correct |
31 |
Correct |
12 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3404 KB |
Output is correct |
2 |
Correct |
3 ms |
3404 KB |
Output is correct |
3 |
Correct |
3 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
3 ms |
3404 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
3 ms |
3404 KB |
Output is correct |
8 |
Correct |
3 ms |
3404 KB |
Output is correct |
9 |
Correct |
4 ms |
3404 KB |
Output is correct |
10 |
Correct |
3 ms |
3404 KB |
Output is correct |
11 |
Correct |
3 ms |
3456 KB |
Output is correct |
12 |
Correct |
3 ms |
3404 KB |
Output is correct |
13 |
Correct |
3 ms |
3404 KB |
Output is correct |
14 |
Correct |
3 ms |
3404 KB |
Output is correct |
15 |
Correct |
3 ms |
3404 KB |
Output is correct |
16 |
Correct |
3 ms |
3404 KB |
Output is correct |
17 |
Correct |
3 ms |
3404 KB |
Output is correct |
18 |
Correct |
3 ms |
3404 KB |
Output is correct |
19 |
Correct |
3 ms |
3404 KB |
Output is correct |
20 |
Correct |
4 ms |
3404 KB |
Output is correct |
21 |
Correct |
3 ms |
3404 KB |
Output is correct |
22 |
Correct |
3 ms |
3456 KB |
Output is correct |
23 |
Correct |
5 ms |
3404 KB |
Output is correct |
24 |
Correct |
6 ms |
3420 KB |
Output is correct |
25 |
Correct |
10 ms |
3496 KB |
Output is correct |
26 |
Correct |
8 ms |
3404 KB |
Output is correct |
27 |
Correct |
8 ms |
3404 KB |
Output is correct |
28 |
Correct |
10 ms |
3404 KB |
Output is correct |
29 |
Correct |
5 ms |
3404 KB |
Output is correct |
30 |
Correct |
13 ms |
3500 KB |
Output is correct |
31 |
Correct |
12 ms |
3404 KB |
Output is correct |
32 |
Correct |
178 ms |
4212 KB |
Output is correct |
33 |
Correct |
145 ms |
4940 KB |
Output is correct |
34 |
Correct |
149 ms |
4608 KB |
Output is correct |
35 |
Correct |
204 ms |
4904 KB |
Output is correct |
36 |
Correct |
192 ms |
4992 KB |
Output is correct |
37 |
Correct |
189 ms |
4940 KB |
Output is correct |
38 |
Correct |
141 ms |
4704 KB |
Output is correct |
39 |
Correct |
145 ms |
4940 KB |
Output is correct |
40 |
Correct |
89 ms |
4172 KB |
Output is correct |
41 |
Correct |
154 ms |
4676 KB |
Output is correct |
42 |
Correct |
219 ms |
4992 KB |
Output is correct |
43 |
Correct |
226 ms |
4940 KB |
Output is correct |
44 |
Correct |
3 ms |
3404 KB |
Output is correct |
45 |
Correct |
3 ms |
3404 KB |
Output is correct |