#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+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 i=1;i<=x;i++){
nxt[i][0]=nxt[i-1][0];
for(int j=1;j<i;j++)
if(max(l[i],l[j])<=min(r[i],r[j]))
nxt[i][0]=max(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[c2][i]>=c1)
c2=nxt[c2][i],ans+=(1<<i);
cout<<ans<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1069 ms |
5372 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
844 KB |
Output is correct |
2 |
Correct |
43 ms |
760 KB |
Output is correct |
3 |
Correct |
45 ms |
672 KB |
Output is correct |
4 |
Correct |
47 ms |
836 KB |
Output is correct |
5 |
Correct |
43 ms |
724 KB |
Output is correct |
6 |
Correct |
22 ms |
672 KB |
Output is correct |
7 |
Correct |
42 ms |
656 KB |
Output is correct |
8 |
Correct |
48 ms |
736 KB |
Output is correct |
9 |
Correct |
37 ms |
804 KB |
Output is correct |
10 |
Correct |
26 ms |
724 KB |
Output is correct |
11 |
Correct |
17 ms |
724 KB |
Output is correct |
12 |
Correct |
15 ms |
772 KB |
Output is correct |
13 |
Correct |
17 ms |
852 KB |
Output is correct |
14 |
Correct |
16 ms |
772 KB |
Output is correct |
15 |
Correct |
16 ms |
840 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
20 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
844 KB |
Output is correct |
2 |
Correct |
43 ms |
760 KB |
Output is correct |
3 |
Correct |
45 ms |
672 KB |
Output is correct |
4 |
Correct |
47 ms |
836 KB |
Output is correct |
5 |
Correct |
43 ms |
724 KB |
Output is correct |
6 |
Correct |
22 ms |
672 KB |
Output is correct |
7 |
Correct |
42 ms |
656 KB |
Output is correct |
8 |
Correct |
48 ms |
736 KB |
Output is correct |
9 |
Correct |
37 ms |
804 KB |
Output is correct |
10 |
Correct |
26 ms |
724 KB |
Output is correct |
11 |
Correct |
17 ms |
724 KB |
Output is correct |
12 |
Correct |
15 ms |
772 KB |
Output is correct |
13 |
Correct |
17 ms |
852 KB |
Output is correct |
14 |
Correct |
16 ms |
772 KB |
Output is correct |
15 |
Correct |
16 ms |
840 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
20 ms |
740 KB |
Output is correct |
18 |
Correct |
108 ms |
1644 KB |
Output is correct |
19 |
Correct |
97 ms |
1612 KB |
Output is correct |
20 |
Correct |
113 ms |
1648 KB |
Output is correct |
21 |
Correct |
107 ms |
1652 KB |
Output is correct |
22 |
Correct |
102 ms |
1656 KB |
Output is correct |
23 |
Correct |
83 ms |
1624 KB |
Output is correct |
24 |
Correct |
102 ms |
1612 KB |
Output is correct |
25 |
Correct |
104 ms |
1636 KB |
Output is correct |
26 |
Correct |
95 ms |
1580 KB |
Output is correct |
27 |
Correct |
80 ms |
1484 KB |
Output is correct |
28 |
Correct |
54 ms |
1228 KB |
Output is correct |
29 |
Correct |
55 ms |
1208 KB |
Output is correct |
30 |
Correct |
57 ms |
1180 KB |
Output is correct |
31 |
Correct |
57 ms |
1180 KB |
Output is correct |
32 |
Correct |
57 ms |
1228 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
63 ms |
2124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1083 ms |
5532 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1069 ms |
5372 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |