#include <bits/stdc++.h>
#define int long long
using namespace std;
int req[200005];
int freq[200005];
int a[200005];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
int n,k,rq; cin>>n>>k>>rq;
for(int i=0; i<n; i++) cin>>a[i];
for(int i=0; i<rq; i++) {
int x,c; cin>>x>>c;
req[x] = c;
}
int l = 1, r = n, ans = -1;
while(l<=r) {
int mid = (l+r)/2;
int cnt = 0;
for(int i=0; i<mid; i++) {
freq[a[i]]++;
if(req[a[i]] && freq[a[i]]==req[a[i]]) cnt++;
}
bool f = 0;
int ind = 0;
for(int i=mid; i<n; i++) {
if(cnt==rq) { f = 1; break; }
if(req[a[ind]] && freq[a[ind]]==req[a[ind]]) cnt--;
freq[a[ind]]--, freq[a[i]]++;
if(req[a[i]] && freq[a[i]]==req[a[i]]) cnt++;
ind++;
}
if(cnt==rq) f = 1;
if(f) { r = mid-1; ans = mid; }
else l = mid+1;
for(int i=0; i<=k; i++) freq[i]=0;
}
if(ans==-1) cout<<"impossible";
else cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2508 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
4700 KB |
Output is correct |
2 |
Correct |
19 ms |
4696 KB |
Output is correct |
3 |
Correct |
11 ms |
4700 KB |
Output is correct |
4 |
Correct |
14 ms |
4700 KB |
Output is correct |
5 |
Correct |
27 ms |
4992 KB |
Output is correct |
6 |
Correct |
12 ms |
4700 KB |
Output is correct |
7 |
Correct |
16 ms |
4744 KB |
Output is correct |
8 |
Correct |
25 ms |
5980 KB |
Output is correct |
9 |
Correct |
16 ms |
5468 KB |
Output is correct |
10 |
Correct |
14 ms |
4952 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2528 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2596 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
4744 KB |
Output is correct |
2 |
Correct |
27 ms |
5000 KB |
Output is correct |
3 |
Correct |
26 ms |
4744 KB |
Output is correct |
4 |
Correct |
9 ms |
4856 KB |
Output is correct |
5 |
Correct |
40 ms |
4744 KB |
Output is correct |
6 |
Correct |
47 ms |
6992 KB |
Output is correct |
7 |
Correct |
18 ms |
5724 KB |
Output is correct |
8 |
Correct |
30 ms |
5724 KB |
Output is correct |
9 |
Correct |
13 ms |
4952 KB |
Output is correct |
10 |
Correct |
19 ms |
4956 KB |
Output is correct |
11 |
Correct |
17 ms |
5084 KB |
Output is correct |
12 |
Correct |
15 ms |
4956 KB |
Output is correct |
13 |
Correct |
21 ms |
5720 KB |
Output is correct |
14 |
Correct |
16 ms |
4952 KB |
Output is correct |
15 |
Correct |
16 ms |
5212 KB |
Output is correct |
16 |
Correct |
25 ms |
5880 KB |
Output is correct |
17 |
Correct |
16 ms |
5624 KB |
Output is correct |
18 |
Correct |
16 ms |
5140 KB |
Output is correct |
19 |
Correct |
1 ms |
2512 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
2 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |