#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define name "main"
const int N=200'000;
int n,k,R;
int d[N+2],q[N+2];
int st[N*4+2];
#define lef(id) id<<1
#define rig(id) id<<1|1
void build(int id,int l,int r){
if (l==r) st[id]=q[l];
else{
int m=l+r>>1;
build(lef(id),l,m);
build(rig(id),m+1,r);
st[id]=max(st[lef(id)],st[rig(id)]);
}
}
void upd(int id,int l,int r,int p,int x){
if (l>p||r<p) return;
if (l==r){
st[id]+=x;
}
else{
int m=l+r>>1;
upd(lef(id),l,m,p,x);
upd(rig(id),m+1,r,p,x);
st[id]=max(st[lef(id)],st[rig(id)]);
}
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>k>>R;
for(int i=1;i<=n;++i) cin>>d[i],++d[i];
for(int i=1;i<=R;++i) {
int t;cin>>t;++t;cin>>q[t];
}
build(1,1,k);
int ans=n+1;
for(int i=1,j=1;i<=n;++i){
while(j<=n&&st[1]>0){
upd(1,1,k,d[j],-1);
++j;
}
if (st[1]==0) ans=min(ans,j-i);
upd(1,1,k,d[i],1);
}
if (ans==n+1){
cout<<"impossible";
exit(0);
}
cout<<ans;
exit(0);
}
Compilation message
dna.cpp: In function 'void build(int, int, int)':
dna.cpp:17:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
17 | int m=l+r>>1;
| ~^~
dna.cpp: In function 'void upd(int, int, int, int, int)':
dna.cpp:29:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
29 | int m=l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2520 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2384 KB |
Output is correct |
4 |
Correct |
3 ms |
2552 KB |
Output is correct |
5 |
Correct |
3 ms |
2640 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2520 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2552 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2516 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
3152 KB |
Output is correct |
2 |
Correct |
12 ms |
3156 KB |
Output is correct |
3 |
Correct |
17 ms |
3356 KB |
Output is correct |
4 |
Correct |
17 ms |
3152 KB |
Output is correct |
5 |
Correct |
72 ms |
6224 KB |
Output is correct |
6 |
Correct |
20 ms |
3152 KB |
Output is correct |
7 |
Correct |
36 ms |
3488 KB |
Output is correct |
8 |
Correct |
82 ms |
6376 KB |
Output is correct |
9 |
Correct |
59 ms |
3920 KB |
Output is correct |
10 |
Correct |
19 ms |
3152 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
2 ms |
2384 KB |
Output is correct |
14 |
Correct |
2 ms |
2384 KB |
Output is correct |
15 |
Correct |
2 ms |
2540 KB |
Output is correct |
16 |
Correct |
1 ms |
2556 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
1 ms |
2512 KB |
Output is correct |
22 |
Correct |
1 ms |
2384 KB |
Output is correct |
23 |
Correct |
1 ms |
2384 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
6736 KB |
Output is correct |
2 |
Correct |
74 ms |
6904 KB |
Output is correct |
3 |
Correct |
69 ms |
6224 KB |
Output is correct |
4 |
Correct |
11 ms |
3152 KB |
Output is correct |
5 |
Correct |
81 ms |
7316 KB |
Output is correct |
6 |
Correct |
88 ms |
6992 KB |
Output is correct |
7 |
Correct |
61 ms |
3920 KB |
Output is correct |
8 |
Correct |
65 ms |
6220 KB |
Output is correct |
9 |
Correct |
15 ms |
3164 KB |
Output is correct |
10 |
Correct |
12 ms |
3096 KB |
Output is correct |
11 |
Correct |
17 ms |
3288 KB |
Output is correct |
12 |
Correct |
16 ms |
3152 KB |
Output is correct |
13 |
Correct |
69 ms |
6224 KB |
Output is correct |
14 |
Correct |
19 ms |
3152 KB |
Output is correct |
15 |
Correct |
30 ms |
3336 KB |
Output is correct |
16 |
Correct |
82 ms |
6224 KB |
Output is correct |
17 |
Correct |
56 ms |
3920 KB |
Output is correct |
18 |
Correct |
19 ms |
3152 KB |
Output is correct |
19 |
Correct |
1 ms |
2400 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
2 ms |
2384 KB |
Output is correct |
22 |
Correct |
2 ms |
2384 KB |
Output is correct |
23 |
Correct |
2 ms |
2384 KB |
Output is correct |
24 |
Correct |
1 ms |
2524 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
1 ms |
2384 KB |
Output is correct |
27 |
Correct |
1 ms |
2516 KB |
Output is correct |
28 |
Correct |
1 ms |
2384 KB |
Output is correct |
29 |
Correct |
1 ms |
2384 KB |
Output is correct |
30 |
Correct |
1 ms |
2384 KB |
Output is correct |
31 |
Correct |
1 ms |
2384 KB |
Output is correct |
32 |
Correct |
1 ms |
2384 KB |
Output is correct |
33 |
Correct |
1 ms |
2384 KB |
Output is correct |