#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5,M=18;
int x,q,l[N],r[N],nxt[N][20];
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin>>x;
for(int i=1;i<=x;i++)cin>>l[i]>>r[i];
for(int j=0;j<=M;j++)nxt[x+1][j]=x+1;
for(int i=x;i>=1;i--){
nxt[i][0]=(i<x?nxt[i+1][0]:i+1);
for(int j=x;j>i;j--)
if(max(l[i],l[j])<=min(r[i],r[j]))
nxt[i][0]=min(nxt[i][0],j);
for(int j=1;j<=M;j++)
nxt[i][j]=nxt[nxt[i][j-1]][j-1];
}
cin>>q;
while(q--){
int c1,c2,ans=1;cin>>c1>>c2;
for(int i=M;i>=0;i--)
if(nxt[c1][i]<=c2)
c1=nxt[c1][i],ans+=(1<<i);
cout<<ans<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
19 ms |
2004 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
700 KB |
Output is correct |
2 |
Correct |
48 ms |
728 KB |
Output is correct |
3 |
Correct |
46 ms |
760 KB |
Output is correct |
4 |
Correct |
50 ms |
672 KB |
Output is correct |
5 |
Correct |
49 ms |
688 KB |
Output is correct |
6 |
Correct |
23 ms |
700 KB |
Output is correct |
7 |
Correct |
41 ms |
672 KB |
Output is correct |
8 |
Correct |
48 ms |
692 KB |
Output is correct |
9 |
Correct |
35 ms |
712 KB |
Output is correct |
10 |
Correct |
28 ms |
692 KB |
Output is correct |
11 |
Correct |
17 ms |
764 KB |
Output is correct |
12 |
Correct |
15 ms |
644 KB |
Output is correct |
13 |
Correct |
20 ms |
740 KB |
Output is correct |
14 |
Correct |
16 ms |
708 KB |
Output is correct |
15 |
Correct |
16 ms |
724 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
20 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
700 KB |
Output is correct |
2 |
Correct |
48 ms |
728 KB |
Output is correct |
3 |
Correct |
46 ms |
760 KB |
Output is correct |
4 |
Correct |
50 ms |
672 KB |
Output is correct |
5 |
Correct |
49 ms |
688 KB |
Output is correct |
6 |
Correct |
23 ms |
700 KB |
Output is correct |
7 |
Correct |
41 ms |
672 KB |
Output is correct |
8 |
Correct |
48 ms |
692 KB |
Output is correct |
9 |
Correct |
35 ms |
712 KB |
Output is correct |
10 |
Correct |
28 ms |
692 KB |
Output is correct |
11 |
Correct |
17 ms |
764 KB |
Output is correct |
12 |
Correct |
15 ms |
644 KB |
Output is correct |
13 |
Correct |
20 ms |
740 KB |
Output is correct |
14 |
Correct |
16 ms |
708 KB |
Output is correct |
15 |
Correct |
16 ms |
724 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
20 ms |
716 KB |
Output is correct |
18 |
Correct |
113 ms |
1636 KB |
Output is correct |
19 |
Correct |
131 ms |
1500 KB |
Output is correct |
20 |
Correct |
113 ms |
1612 KB |
Output is correct |
21 |
Correct |
100 ms |
1424 KB |
Output is correct |
22 |
Correct |
99 ms |
1536 KB |
Output is correct |
23 |
Correct |
74 ms |
1484 KB |
Output is correct |
24 |
Correct |
102 ms |
1576 KB |
Output is correct |
25 |
Correct |
98 ms |
1484 KB |
Output is correct |
26 |
Correct |
100 ms |
1516 KB |
Output is correct |
27 |
Correct |
81 ms |
1448 KB |
Output is correct |
28 |
Correct |
54 ms |
1088 KB |
Output is correct |
29 |
Correct |
59 ms |
1052 KB |
Output is correct |
30 |
Correct |
55 ms |
1100 KB |
Output is correct |
31 |
Correct |
55 ms |
1056 KB |
Output is correct |
32 |
Correct |
56 ms |
1080 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
64 ms |
2208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
21 ms |
2012 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
19 ms |
2004 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |