#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#define ll long long
using namespace std;
struct node{
ll val,tag;
};
vector<node> seg;
void push(ll l,ll r,int ind){
if(l==r) return;
ll mid=(l+r)>>1;
seg[ind*2].val+=(mid-l+1)*seg[ind].tag;
seg[ind*2+1].val+=(r-mid)*seg[ind].tag;
seg[ind*2].tag+=seg[ind].tag;
seg[ind*2+1].tag+=seg[ind].tag;
seg[ind].tag=0;
}
ll query(ll l,ll r,int start,int end,int ind){
if(r<start||end<l) return 0;
if(start<=l&&r<=end){
return seg[ind].val;
}
ll mid=(l+r)>>1;
push(l,r,ind);
return query(l,mid,start,end,ind*2)+query(mid+1,r,start,end,ind*2+1);
}
void modify(ll l,ll r,int start,int end,ll num,int ind){
if(r<start||end<l) return;
if(start<=l&&r<=end){
seg[ind].val+=(r-l+1)*num;
seg[ind].tag+=num;
return;
}
ll mid=(l+r)>>1;
push(l,r,ind);
modify(l,mid,start,end,num,ind*2);
modify(mid+1,r,start,end,num,ind*2+1);
seg[ind].val=(seg[ind*2].val+seg[ind*2+1].val);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,q;
cin>>n;
vector<pair<ll,ll>> vec(n+1);
for(int i=1;i<=n;i++) cin>>vec[i].first>>vec[i].second;
vector<ll> cc;
for(int i=1;i<=n;i++){
cc.push_back(vec[i].first);
cc.push_back(vec[i].second);
}
sort(cc.begin(),cc.end());
cc.resize(unique(cc.begin(),cc.end())-cc.begin());
for(int i=1;i<=n;i++){
vec[i].first=lower_bound(cc.begin(),cc.end(),vec[i].first)-cc.begin()+1;
vec[i].second=lower_bound(cc.begin(),cc.end(),vec[i].second)-cc.begin()+1;
}
vector<int> far(n+1);
seg.resize(4*cc.size()+4);
ll len=cc.size()+1;
int ii=1;
for(int i=1;i<=n;i++){
while(ii<=n&&query(1,len,vec[ii].first,vec[ii].second,1)==0) modify(1,len,vec[ii].first,vec[ii].second,1,1),ii++;
far[i]=ii;
modify(1,len,vec[i].first,vec[i].second,-1,1);
}
int a,b;
cin>>q;
for(int i=0;i<q;i++){
cin>>a>>b;
int ans=0;
while(a<=b){
a=far[a];
ans++;
}
cout<<ans<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
490 ms |
34676 KB |
Output is correct |
2 |
Correct |
471 ms |
34108 KB |
Output is correct |
3 |
Correct |
475 ms |
34232 KB |
Output is correct |
4 |
Correct |
494 ms |
34684 KB |
Output is correct |
5 |
Correct |
503 ms |
36156 KB |
Output is correct |
6 |
Correct |
52 ms |
10944 KB |
Output is correct |
7 |
Correct |
63 ms |
11000 KB |
Output is correct |
8 |
Correct |
65 ms |
10908 KB |
Output is correct |
9 |
Correct |
75 ms |
11204 KB |
Output is correct |
10 |
Correct |
80 ms |
10864 KB |
Output is correct |
11 |
Correct |
331 ms |
34968 KB |
Output is correct |
12 |
Correct |
299 ms |
32704 KB |
Output is correct |
13 |
Correct |
281 ms |
32592 KB |
Output is correct |
14 |
Correct |
330 ms |
34944 KB |
Output is correct |
15 |
Correct |
317 ms |
33980 KB |
Output is correct |
16 |
Correct |
0 ms |
316 KB |
Output is correct |
17 |
Correct |
59 ms |
11388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1380 KB |
Output is correct |
2 |
Correct |
20 ms |
1328 KB |
Output is correct |
3 |
Correct |
20 ms |
1236 KB |
Output is correct |
4 |
Correct |
21 ms |
1364 KB |
Output is correct |
5 |
Correct |
20 ms |
1320 KB |
Output is correct |
6 |
Correct |
18 ms |
776 KB |
Output is correct |
7 |
Correct |
13 ms |
744 KB |
Output is correct |
8 |
Correct |
11 ms |
780 KB |
Output is correct |
9 |
Correct |
10 ms |
724 KB |
Output is correct |
10 |
Correct |
7 ms |
724 KB |
Output is correct |
11 |
Correct |
6 ms |
1244 KB |
Output is correct |
12 |
Correct |
6 ms |
1224 KB |
Output is correct |
13 |
Correct |
7 ms |
1236 KB |
Output is correct |
14 |
Correct |
8 ms |
1340 KB |
Output is correct |
15 |
Correct |
7 ms |
1356 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
49 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1380 KB |
Output is correct |
2 |
Correct |
20 ms |
1328 KB |
Output is correct |
3 |
Correct |
20 ms |
1236 KB |
Output is correct |
4 |
Correct |
21 ms |
1364 KB |
Output is correct |
5 |
Correct |
20 ms |
1320 KB |
Output is correct |
6 |
Correct |
18 ms |
776 KB |
Output is correct |
7 |
Correct |
13 ms |
744 KB |
Output is correct |
8 |
Correct |
11 ms |
780 KB |
Output is correct |
9 |
Correct |
10 ms |
724 KB |
Output is correct |
10 |
Correct |
7 ms |
724 KB |
Output is correct |
11 |
Correct |
6 ms |
1244 KB |
Output is correct |
12 |
Correct |
6 ms |
1224 KB |
Output is correct |
13 |
Correct |
7 ms |
1236 KB |
Output is correct |
14 |
Correct |
8 ms |
1340 KB |
Output is correct |
15 |
Correct |
7 ms |
1356 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
49 ms |
756 KB |
Output is correct |
18 |
Correct |
510 ms |
3904 KB |
Output is correct |
19 |
Correct |
448 ms |
3660 KB |
Output is correct |
20 |
Correct |
523 ms |
4172 KB |
Output is correct |
21 |
Correct |
452 ms |
3828 KB |
Output is correct |
22 |
Correct |
469 ms |
3860 KB |
Output is correct |
23 |
Correct |
592 ms |
3476 KB |
Output is correct |
24 |
Correct |
446 ms |
3328 KB |
Output is correct |
25 |
Correct |
354 ms |
3396 KB |
Output is correct |
26 |
Correct |
280 ms |
3256 KB |
Output is correct |
27 |
Correct |
196 ms |
3020 KB |
Output is correct |
28 |
Correct |
43 ms |
3312 KB |
Output is correct |
29 |
Correct |
44 ms |
3412 KB |
Output is correct |
30 |
Correct |
44 ms |
3340 KB |
Output is correct |
31 |
Correct |
45 ms |
3368 KB |
Output is correct |
32 |
Correct |
45 ms |
3404 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Execution timed out |
1085 ms |
2508 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
535 ms |
36284 KB |
Output is correct |
2 |
Correct |
504 ms |
35512 KB |
Output is correct |
3 |
Correct |
471 ms |
33104 KB |
Output is correct |
4 |
Correct |
461 ms |
32680 KB |
Output is correct |
5 |
Correct |
472 ms |
33664 KB |
Output is correct |
6 |
Correct |
63 ms |
10968 KB |
Output is correct |
7 |
Correct |
71 ms |
10932 KB |
Output is correct |
8 |
Correct |
69 ms |
10836 KB |
Output is correct |
9 |
Correct |
73 ms |
10820 KB |
Output is correct |
10 |
Correct |
88 ms |
11304 KB |
Output is correct |
11 |
Correct |
268 ms |
32568 KB |
Output is correct |
12 |
Correct |
322 ms |
35692 KB |
Output is correct |
13 |
Correct |
299 ms |
32448 KB |
Output is correct |
14 |
Correct |
329 ms |
33436 KB |
Output is correct |
15 |
Correct |
332 ms |
35396 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
90 ms |
11008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
490 ms |
34676 KB |
Output is correct |
2 |
Correct |
471 ms |
34108 KB |
Output is correct |
3 |
Correct |
475 ms |
34232 KB |
Output is correct |
4 |
Correct |
494 ms |
34684 KB |
Output is correct |
5 |
Correct |
503 ms |
36156 KB |
Output is correct |
6 |
Correct |
52 ms |
10944 KB |
Output is correct |
7 |
Correct |
63 ms |
11000 KB |
Output is correct |
8 |
Correct |
65 ms |
10908 KB |
Output is correct |
9 |
Correct |
75 ms |
11204 KB |
Output is correct |
10 |
Correct |
80 ms |
10864 KB |
Output is correct |
11 |
Correct |
331 ms |
34968 KB |
Output is correct |
12 |
Correct |
299 ms |
32704 KB |
Output is correct |
13 |
Correct |
281 ms |
32592 KB |
Output is correct |
14 |
Correct |
330 ms |
34944 KB |
Output is correct |
15 |
Correct |
317 ms |
33980 KB |
Output is correct |
16 |
Correct |
0 ms |
316 KB |
Output is correct |
17 |
Correct |
59 ms |
11388 KB |
Output is correct |
18 |
Correct |
21 ms |
1380 KB |
Output is correct |
19 |
Correct |
20 ms |
1328 KB |
Output is correct |
20 |
Correct |
20 ms |
1236 KB |
Output is correct |
21 |
Correct |
21 ms |
1364 KB |
Output is correct |
22 |
Correct |
20 ms |
1320 KB |
Output is correct |
23 |
Correct |
18 ms |
776 KB |
Output is correct |
24 |
Correct |
13 ms |
744 KB |
Output is correct |
25 |
Correct |
11 ms |
780 KB |
Output is correct |
26 |
Correct |
10 ms |
724 KB |
Output is correct |
27 |
Correct |
7 ms |
724 KB |
Output is correct |
28 |
Correct |
6 ms |
1244 KB |
Output is correct |
29 |
Correct |
6 ms |
1224 KB |
Output is correct |
30 |
Correct |
7 ms |
1236 KB |
Output is correct |
31 |
Correct |
8 ms |
1340 KB |
Output is correct |
32 |
Correct |
7 ms |
1356 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
49 ms |
756 KB |
Output is correct |
35 |
Correct |
510 ms |
3904 KB |
Output is correct |
36 |
Correct |
448 ms |
3660 KB |
Output is correct |
37 |
Correct |
523 ms |
4172 KB |
Output is correct |
38 |
Correct |
452 ms |
3828 KB |
Output is correct |
39 |
Correct |
469 ms |
3860 KB |
Output is correct |
40 |
Correct |
592 ms |
3476 KB |
Output is correct |
41 |
Correct |
446 ms |
3328 KB |
Output is correct |
42 |
Correct |
354 ms |
3396 KB |
Output is correct |
43 |
Correct |
280 ms |
3256 KB |
Output is correct |
44 |
Correct |
196 ms |
3020 KB |
Output is correct |
45 |
Correct |
43 ms |
3312 KB |
Output is correct |
46 |
Correct |
44 ms |
3412 KB |
Output is correct |
47 |
Correct |
44 ms |
3340 KB |
Output is correct |
48 |
Correct |
45 ms |
3368 KB |
Output is correct |
49 |
Correct |
45 ms |
3404 KB |
Output is correct |
50 |
Correct |
0 ms |
340 KB |
Output is correct |
51 |
Execution timed out |
1085 ms |
2508 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |