#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=2e5+10;
const int SS=1<<18;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=18;
pair<int,int> sorted[N],t[N];
int seg[(SS<<1)+10],lazy[(SS<<1)+10],nxt[N],jump[N][L+1];
void push(int v){
lazy[(v<<1)]+=lazy[v],lazy[(v<<1)+1]+=lazy[v];
seg[(v<<1)]+=lazy[v],seg[(v<<1)+1]+=lazy[v];
lazy[v]=0;
}
void upd(int a,int b,int x,int p=0,int k=SS-1,int v=1){
if(p>b or k<a) return;
if(p>=a and k<=b){
seg[v]+=x,lazy[v]+=x;
return;
}
push(v);
upd(a,b,x,p,(p+k)>>1,(v<<1)),upd(a,b,x,((p+k)>>1)+1,k,(v<<1)+1);
seg[v]=max(seg[(v<<1)],seg[(v<<1)+1]);
}
int Query(int a,int b,int p=0,int k=SS-1,int v=1){
if(p>b or k<a) return 0;
if(p>=a and k<=b) return seg[v];
push(v);
return max(Query(a,b,p,(p+k)>>1,v<<1),Query(a,b,((p+k)>>1)+1,k,(v<<1)+1));
}
void solve(){
int n;
cin>>n;
int curr=0;
for(int a,b,i=1;i<=n;i++){
cin>>a>>b;
sorted[++curr]={a,i},sorted[++curr]={b,-i};
}
sort(sorted+1,sorted+1+curr);
int l=0;
for(int i=1;i<=curr;i++){
if(sorted[i].fi!=sorted[i-1].fi or i==1) l++;
if(sorted[i].se>0) t[sorted[i].se].fi=l;
else t[sorted[i].se*(-1)].se=l;
}
curr=0;
for(int i=1;i<=n;i++){
curr=max(curr,i);
while(curr<=n and Query(t[curr].fi,t[curr].se)==0){
upd(t[curr].fi,t[curr].se,1);
++curr;
}
nxt[i]=curr;
upd(t[i].fi,t[i].se,-1);
jump[i][0]=nxt[i];
}
for(int i=0;i<=L;i++) jump[n+1][i]=n+1;
for(int i=n;i>=1;i--)
for(int k=1;k<=L;k++) jump[i][k]=jump[jump[i][k-1]][k-1];
int q;
cin>>q;
while(q--){
int a,b;
cin>>a>>b;
int res=1;
for(int i=L;i>=0;i--)
if(jump[a][i]<=b) res+=(1<<i),a=jump[a][i];
cout<<res<<"\n";
}
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
int tt=1;
while(tt--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
24 ms |
5776 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1248 KB |
Output is correct |
2 |
Correct |
11 ms |
1224 KB |
Output is correct |
3 |
Correct |
12 ms |
1108 KB |
Output is correct |
4 |
Correct |
11 ms |
1236 KB |
Output is correct |
5 |
Correct |
10 ms |
1108 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
7 ms |
980 KB |
Output is correct |
8 |
Correct |
8 ms |
980 KB |
Output is correct |
9 |
Correct |
7 ms |
984 KB |
Output is correct |
10 |
Correct |
7 ms |
980 KB |
Output is correct |
11 |
Correct |
7 ms |
1160 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
6 ms |
1208 KB |
Output is correct |
14 |
Correct |
7 ms |
1236 KB |
Output is correct |
15 |
Correct |
7 ms |
1232 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
7 ms |
1096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1248 KB |
Output is correct |
2 |
Correct |
11 ms |
1224 KB |
Output is correct |
3 |
Correct |
12 ms |
1108 KB |
Output is correct |
4 |
Correct |
11 ms |
1236 KB |
Output is correct |
5 |
Correct |
10 ms |
1108 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
7 ms |
980 KB |
Output is correct |
8 |
Correct |
8 ms |
980 KB |
Output is correct |
9 |
Correct |
7 ms |
984 KB |
Output is correct |
10 |
Correct |
7 ms |
980 KB |
Output is correct |
11 |
Correct |
7 ms |
1160 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
6 ms |
1208 KB |
Output is correct |
14 |
Correct |
7 ms |
1236 KB |
Output is correct |
15 |
Correct |
7 ms |
1232 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
7 ms |
1096 KB |
Output is correct |
18 |
Correct |
80 ms |
3908 KB |
Output is correct |
19 |
Correct |
71 ms |
3552 KB |
Output is correct |
20 |
Correct |
77 ms |
3932 KB |
Output is correct |
21 |
Correct |
72 ms |
3636 KB |
Output is correct |
22 |
Correct |
76 ms |
3692 KB |
Output is correct |
23 |
Correct |
64 ms |
3404 KB |
Output is correct |
24 |
Correct |
70 ms |
3560 KB |
Output is correct |
25 |
Correct |
70 ms |
3664 KB |
Output is correct |
26 |
Correct |
66 ms |
3532 KB |
Output is correct |
27 |
Correct |
68 ms |
3492 KB |
Output is correct |
28 |
Correct |
47 ms |
3148 KB |
Output is correct |
29 |
Correct |
51 ms |
3252 KB |
Output is correct |
30 |
Correct |
50 ms |
3324 KB |
Output is correct |
31 |
Correct |
52 ms |
3240 KB |
Output is correct |
32 |
Correct |
53 ms |
3276 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
57 ms |
3312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
22 ms |
5704 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
24 ms |
5776 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |