#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3HspL4A ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vec(int);
void print(){cout<<"\n";}
template<class T,class...E>
void print(const T&v,const E&...u){cout<<v<<' ',print(u...);}
// e
using vp=vec(pii);
const int inf=1e9+11;
int cross(int a,int b,int c,int d){
if(c>=a and c<=b) return 1;
if(a>=c and a<=d) return 1;
if(d>=a and d<=b) return 1;
if(b>=c and b<=d) return 1;
return 0;
}
signed main(){
_3HspL4A;
int n;
cin>>n;
vp a(n);
rep(i,n){
cin>>a[i].fi>>a[i].se;
}
vi tmp;
rep(i,n){
tmp.pb(a[i].fi);
tmp.pb(a[i].se);
}
sort(tmp.begin(),tmp.end());
tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
rep(i,n){
a[i].fi=lower_bound(tmp.begin(),tmp.end(),a[i].fi)-tmp.begin();
a[i].se=lower_bound(tmp.begin(),tmp.end(),a[i].se)-tmp.begin();
}
const int m=sz(tmp);
multiset<pii> mst;
vi nxt(n,-1);
int j=0;
rep(i,n){
pii p=a[i];
nxt[i]=i+1;
if(!sz(mst)){
mst.insert(p);
}else{
vi c={p.fi,p.se};
while(1){
bool pok=1;
for(auto v:c){
auto it=mst.lower_bound({v,-inf});
if(it!=mst.end()){
if(cross(it->fi,it->se,p.fi,p.se)) pok=0;
}
if(it!=mst.begin()){
it=prev(it);
if(cross(it->fi,it->se,p.fi,p.se)) pok=0;
}
}
if(pok) break;
mst.erase(mst.find({a[j].fi,a[j].se}));
nxt[j]=i;
j=j+1;
}
mst.insert(p);
}
}
rng(k,j,n){
nxt[k]=n;
}
int q;
cin>>q;
rep(_,q){
int s,t;
cin>>s>>t;
s-=1;
int i=s;
int ans=0;
while(1){
if(i>=t) break;
ans++;
i=nxt[i];
}
print(ans);
}
//
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:52:12: warning: unused variable 'm' [-Wunused-variable]
52 | const int m=sz(tmp);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
4168 KB |
Output is correct |
2 |
Correct |
153 ms |
7600 KB |
Output is correct |
3 |
Correct |
147 ms |
7660 KB |
Output is correct |
4 |
Correct |
146 ms |
7680 KB |
Output is correct |
5 |
Correct |
161 ms |
8072 KB |
Output is correct |
6 |
Correct |
68 ms |
7348 KB |
Output is correct |
7 |
Correct |
86 ms |
7500 KB |
Output is correct |
8 |
Correct |
69 ms |
7384 KB |
Output is correct |
9 |
Correct |
83 ms |
7628 KB |
Output is correct |
10 |
Correct |
88 ms |
7368 KB |
Output is correct |
11 |
Correct |
241 ms |
16460 KB |
Output is correct |
12 |
Correct |
260 ms |
15540 KB |
Output is correct |
13 |
Correct |
237 ms |
15412 KB |
Output is correct |
14 |
Correct |
288 ms |
12572 KB |
Output is correct |
15 |
Correct |
242 ms |
11128 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
63 ms |
7876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
572 KB |
Output is correct |
2 |
Correct |
18 ms |
596 KB |
Output is correct |
3 |
Correct |
18 ms |
600 KB |
Output is correct |
4 |
Correct |
18 ms |
608 KB |
Output is correct |
5 |
Correct |
18 ms |
584 KB |
Output is correct |
6 |
Correct |
18 ms |
612 KB |
Output is correct |
7 |
Correct |
14 ms |
616 KB |
Output is correct |
8 |
Correct |
12 ms |
616 KB |
Output is correct |
9 |
Correct |
11 ms |
608 KB |
Output is correct |
10 |
Correct |
8 ms |
584 KB |
Output is correct |
11 |
Correct |
6 ms |
776 KB |
Output is correct |
12 |
Correct |
6 ms |
724 KB |
Output is correct |
13 |
Correct |
6 ms |
760 KB |
Output is correct |
14 |
Correct |
8 ms |
596 KB |
Output is correct |
15 |
Correct |
6 ms |
596 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
50 ms |
608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
572 KB |
Output is correct |
2 |
Correct |
18 ms |
596 KB |
Output is correct |
3 |
Correct |
18 ms |
600 KB |
Output is correct |
4 |
Correct |
18 ms |
608 KB |
Output is correct |
5 |
Correct |
18 ms |
584 KB |
Output is correct |
6 |
Correct |
18 ms |
612 KB |
Output is correct |
7 |
Correct |
14 ms |
616 KB |
Output is correct |
8 |
Correct |
12 ms |
616 KB |
Output is correct |
9 |
Correct |
11 ms |
608 KB |
Output is correct |
10 |
Correct |
8 ms |
584 KB |
Output is correct |
11 |
Correct |
6 ms |
776 KB |
Output is correct |
12 |
Correct |
6 ms |
724 KB |
Output is correct |
13 |
Correct |
6 ms |
760 KB |
Output is correct |
14 |
Correct |
8 ms |
596 KB |
Output is correct |
15 |
Correct |
6 ms |
596 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
50 ms |
608 KB |
Output is correct |
18 |
Correct |
564 ms |
3440 KB |
Output is correct |
19 |
Correct |
481 ms |
3164 KB |
Output is correct |
20 |
Correct |
564 ms |
3404 KB |
Output is correct |
21 |
Correct |
492 ms |
3236 KB |
Output is correct |
22 |
Correct |
519 ms |
3352 KB |
Output is correct |
23 |
Correct |
657 ms |
3244 KB |
Output is correct |
24 |
Correct |
491 ms |
3380 KB |
Output is correct |
25 |
Correct |
400 ms |
3404 KB |
Output is correct |
26 |
Correct |
305 ms |
3248 KB |
Output is correct |
27 |
Correct |
209 ms |
3148 KB |
Output is correct |
28 |
Correct |
52 ms |
2892 KB |
Output is correct |
29 |
Correct |
57 ms |
3020 KB |
Output is correct |
30 |
Correct |
48 ms |
3104 KB |
Output is correct |
31 |
Correct |
52 ms |
2872 KB |
Output is correct |
32 |
Correct |
53 ms |
2836 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Execution timed out |
1089 ms |
2160 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
4416 KB |
Output is correct |
2 |
Correct |
155 ms |
7812 KB |
Output is correct |
3 |
Correct |
148 ms |
7368 KB |
Output is correct |
4 |
Correct |
160 ms |
7348 KB |
Output is correct |
5 |
Correct |
163 ms |
7624 KB |
Output is correct |
6 |
Correct |
74 ms |
7488 KB |
Output is correct |
7 |
Correct |
73 ms |
7368 KB |
Output is correct |
8 |
Correct |
77 ms |
7364 KB |
Output is correct |
9 |
Correct |
86 ms |
7344 KB |
Output is correct |
10 |
Correct |
95 ms |
7720 KB |
Output is correct |
11 |
Correct |
229 ms |
15412 KB |
Output is correct |
12 |
Correct |
332 ms |
16836 KB |
Output is correct |
13 |
Correct |
229 ms |
15332 KB |
Output is correct |
14 |
Correct |
257 ms |
11276 KB |
Output is correct |
15 |
Correct |
301 ms |
12600 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
92 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
4168 KB |
Output is correct |
2 |
Correct |
153 ms |
7600 KB |
Output is correct |
3 |
Correct |
147 ms |
7660 KB |
Output is correct |
4 |
Correct |
146 ms |
7680 KB |
Output is correct |
5 |
Correct |
161 ms |
8072 KB |
Output is correct |
6 |
Correct |
68 ms |
7348 KB |
Output is correct |
7 |
Correct |
86 ms |
7500 KB |
Output is correct |
8 |
Correct |
69 ms |
7384 KB |
Output is correct |
9 |
Correct |
83 ms |
7628 KB |
Output is correct |
10 |
Correct |
88 ms |
7368 KB |
Output is correct |
11 |
Correct |
241 ms |
16460 KB |
Output is correct |
12 |
Correct |
260 ms |
15540 KB |
Output is correct |
13 |
Correct |
237 ms |
15412 KB |
Output is correct |
14 |
Correct |
288 ms |
12572 KB |
Output is correct |
15 |
Correct |
242 ms |
11128 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
63 ms |
7876 KB |
Output is correct |
18 |
Correct |
18 ms |
572 KB |
Output is correct |
19 |
Correct |
18 ms |
596 KB |
Output is correct |
20 |
Correct |
18 ms |
600 KB |
Output is correct |
21 |
Correct |
18 ms |
608 KB |
Output is correct |
22 |
Correct |
18 ms |
584 KB |
Output is correct |
23 |
Correct |
18 ms |
612 KB |
Output is correct |
24 |
Correct |
14 ms |
616 KB |
Output is correct |
25 |
Correct |
12 ms |
616 KB |
Output is correct |
26 |
Correct |
11 ms |
608 KB |
Output is correct |
27 |
Correct |
8 ms |
584 KB |
Output is correct |
28 |
Correct |
6 ms |
776 KB |
Output is correct |
29 |
Correct |
6 ms |
724 KB |
Output is correct |
30 |
Correct |
6 ms |
760 KB |
Output is correct |
31 |
Correct |
8 ms |
596 KB |
Output is correct |
32 |
Correct |
6 ms |
596 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
50 ms |
608 KB |
Output is correct |
35 |
Correct |
564 ms |
3440 KB |
Output is correct |
36 |
Correct |
481 ms |
3164 KB |
Output is correct |
37 |
Correct |
564 ms |
3404 KB |
Output is correct |
38 |
Correct |
492 ms |
3236 KB |
Output is correct |
39 |
Correct |
519 ms |
3352 KB |
Output is correct |
40 |
Correct |
657 ms |
3244 KB |
Output is correct |
41 |
Correct |
491 ms |
3380 KB |
Output is correct |
42 |
Correct |
400 ms |
3404 KB |
Output is correct |
43 |
Correct |
305 ms |
3248 KB |
Output is correct |
44 |
Correct |
209 ms |
3148 KB |
Output is correct |
45 |
Correct |
52 ms |
2892 KB |
Output is correct |
46 |
Correct |
57 ms |
3020 KB |
Output is correct |
47 |
Correct |
48 ms |
3104 KB |
Output is correct |
48 |
Correct |
52 ms |
2872 KB |
Output is correct |
49 |
Correct |
53 ms |
2836 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Execution timed out |
1089 ms |
2160 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |