#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const ll MOD=1e9+7;
using namespace std;
ll N,M,K,a[200005];
vector <ll> vec[200005];
vector <pair<ll,ll> > pr[200005];
int main(){
cin>>N>>M>>K;
for(int i=1;i<=N;i++){
cin>>a[i];
vec[a[i]].push_back(i);
}
bool ok=true;
for(int i=1;i<=K;i++){
ll x,y;
cin>>x>>y;
// cout<<vec[x].size()<<' '<<y<<endl;
if(vec[x].size()<y){
ok=false;
}
else{
for(int j=y-1;j<vec[x].size();j++){
pr[i].push_back({vec[x][j-(y-1)],vec[x][j]});
}
}
}
if(!ok){
cout<<"impossible"<<endl;
return 0;
}
ll minn=1e18;
for(int i=1;i<=N;i++){
ll maks=0;
bool ok=true;
for(int j=1;j<=K;j++){
ll l=0;
ll r=pr[j].size()-1;
ll ans=-1;
while(l<=r){
ll m=(l+r)/2;
if(pr[j][m].fi>=i){
ans=m;
r=m-1;
}
else{
l=m+1;
}
}
if(ans==-1){
ok=false;
break;
}
maks=max(maks,pr[j][ans].se);
}
if(ok){
minn=min(minn,maks-i+1);
}
}
cout<<minn<<endl;
}
Compilation message
dna.cpp: In function 'int main()':
dna.cpp:22:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
22 | if(vec[x].size()<y){
| ~~~~~~~~~~~~~^~
dna.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int j=y-1;j<vec[x].size();j++){
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9696 KB |
Output is correct |
5 |
Correct |
5 ms |
9700 KB |
Output is correct |
6 |
Correct |
5 ms |
9644 KB |
Output is correct |
7 |
Correct |
5 ms |
9704 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
5 ms |
9684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9812 KB |
Output is correct |
2 |
Correct |
6 ms |
9840 KB |
Output is correct |
3 |
Correct |
6 ms |
9812 KB |
Output is correct |
4 |
Correct |
6 ms |
9840 KB |
Output is correct |
5 |
Correct |
7 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9684 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
6 ms |
9684 KB |
Output is correct |
10 |
Correct |
6 ms |
9684 KB |
Output is correct |
11 |
Correct |
5 ms |
9684 KB |
Output is correct |
12 |
Correct |
5 ms |
9684 KB |
Output is correct |
13 |
Correct |
6 ms |
9684 KB |
Output is correct |
14 |
Correct |
5 ms |
9684 KB |
Output is correct |
15 |
Correct |
5 ms |
9636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
14980 KB |
Output is correct |
2 |
Correct |
51 ms |
17148 KB |
Output is correct |
3 |
Correct |
78 ms |
16140 KB |
Output is correct |
4 |
Correct |
68 ms |
15540 KB |
Output is correct |
5 |
Correct |
72 ms |
15316 KB |
Output is correct |
6 |
Correct |
33 ms |
13704 KB |
Output is correct |
7 |
Correct |
39 ms |
13900 KB |
Output is correct |
8 |
Correct |
86 ms |
18692 KB |
Output is correct |
9 |
Correct |
63 ms |
14616 KB |
Output is correct |
10 |
Correct |
82 ms |
15660 KB |
Output is correct |
11 |
Correct |
6 ms |
9828 KB |
Output is correct |
12 |
Correct |
7 ms |
9812 KB |
Output is correct |
13 |
Correct |
6 ms |
9812 KB |
Output is correct |
14 |
Correct |
7 ms |
9812 KB |
Output is correct |
15 |
Correct |
6 ms |
9712 KB |
Output is correct |
16 |
Correct |
7 ms |
9860 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9684 KB |
Output is correct |
20 |
Correct |
5 ms |
9708 KB |
Output is correct |
21 |
Correct |
5 ms |
9684 KB |
Output is correct |
22 |
Correct |
5 ms |
9684 KB |
Output is correct |
23 |
Correct |
5 ms |
9684 KB |
Output is correct |
24 |
Correct |
5 ms |
9684 KB |
Output is correct |
25 |
Correct |
5 ms |
9632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2065 ms |
21132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |