#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<cassert>
#include<limits.h>
#include<cmath>
#include<set>
#include<numeric> //gcd(a,b)
#include<algorithm>
#include<bitset>
#include<stack>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
#define int long long
const int mod=1e9+7,mxn=2e5,lg=30,inf=1e18,minf=-1e18,Mxn=2e6,root=700;
void setIO(string name){
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
vector<int>pos[mxn+10];
int need[mxn+10],curl[mxn+10];
bool on[mxn+10];
int32_t main(){
fastio
int n,k,r;cin>>n>>k>>r;
vector<int>v(n),l(n,minf);
for(int i=0;i<n;i++)cin>>v[i],pos[v[i]].pb(i);
priority_queue<pii,vector<pii>,greater<pii>>pq;//min left col
while(r--){
int a,b;cin>>a>>b;
curl[a]=minf;
on[a]=1;
pq.push({minf,a});
for(int j=b-1;j<pos[a].size();j++)l[pos[a][j]]=pos[a][j-b+1];
}
int ans=inf;
for(int i=0;i<n;i++){
if(!on[v[i]])continue;
pq.push({l[i],v[i]});
curl[v[i]]=l[i];
while(!pq.empty()&&pq.top().f!=curl[pq.top().s])pq.pop();
if(!pq.empty()&&pq.top().f!=minf)ans=min(ans,i-pq.top().f+1);
}
if(ans==inf)cout<<"impossible";
else cout<<ans;
}
Compilation message
dna.cpp: In function 'int32_t main()':
dna.cpp:54:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int j=b-1;j<pos[a].size();j++)l[pos[a][j]]=pos[a][j-b+1];
| ~^~~~~~~~~~~~~~
dna.cpp: In function 'void setIO(std::string)':
dna.cpp:37:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dna.cpp:38:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8284 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
2 ms |
8284 KB |
Output is correct |
5 |
Correct |
2 ms |
8284 KB |
Output is correct |
6 |
Correct |
3 ms |
8284 KB |
Output is correct |
7 |
Correct |
2 ms |
8280 KB |
Output is correct |
8 |
Correct |
2 ms |
8284 KB |
Output is correct |
9 |
Correct |
2 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8284 KB |
Output is correct |
2 |
Correct |
2 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
3 ms |
8284 KB |
Output is correct |
5 |
Correct |
2 ms |
8284 KB |
Output is correct |
6 |
Correct |
2 ms |
8284 KB |
Output is correct |
7 |
Correct |
2 ms |
8304 KB |
Output is correct |
8 |
Correct |
2 ms |
8280 KB |
Output is correct |
9 |
Correct |
2 ms |
8284 KB |
Output is correct |
10 |
Correct |
2 ms |
8284 KB |
Output is correct |
11 |
Correct |
2 ms |
8284 KB |
Output is correct |
12 |
Correct |
2 ms |
8284 KB |
Output is correct |
13 |
Correct |
2 ms |
8280 KB |
Output is correct |
14 |
Correct |
2 ms |
8284 KB |
Output is correct |
15 |
Correct |
2 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
15552 KB |
Output is correct |
2 |
Correct |
17 ms |
15044 KB |
Output is correct |
3 |
Correct |
16 ms |
13772 KB |
Output is correct |
4 |
Correct |
21 ms |
14876 KB |
Output is correct |
5 |
Correct |
31 ms |
15564 KB |
Output is correct |
6 |
Correct |
31 ms |
19892 KB |
Output is correct |
7 |
Correct |
13 ms |
14400 KB |
Output is correct |
8 |
Correct |
28 ms |
18816 KB |
Output is correct |
9 |
Correct |
22 ms |
14676 KB |
Output is correct |
10 |
Correct |
30 ms |
15768 KB |
Output is correct |
11 |
Correct |
2 ms |
8284 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8472 KB |
Output is correct |
14 |
Correct |
2 ms |
8284 KB |
Output is correct |
15 |
Correct |
2 ms |
8284 KB |
Output is correct |
16 |
Correct |
2 ms |
8308 KB |
Output is correct |
17 |
Correct |
2 ms |
8284 KB |
Output is correct |
18 |
Correct |
2 ms |
8284 KB |
Output is correct |
19 |
Correct |
2 ms |
8284 KB |
Output is correct |
20 |
Correct |
2 ms |
8284 KB |
Output is correct |
21 |
Correct |
2 ms |
8284 KB |
Output is correct |
22 |
Correct |
2 ms |
8284 KB |
Output is correct |
23 |
Correct |
2 ms |
8088 KB |
Output is correct |
24 |
Correct |
2 ms |
8280 KB |
Output is correct |
25 |
Correct |
2 ms |
8476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
20680 KB |
Output is correct |
2 |
Correct |
65 ms |
18088 KB |
Output is correct |
3 |
Correct |
34 ms |
16740 KB |
Output is correct |
4 |
Correct |
16 ms |
13548 KB |
Output is correct |
5 |
Correct |
45 ms |
22352 KB |
Output is correct |
6 |
Correct |
66 ms |
25024 KB |
Output is correct |
7 |
Correct |
38 ms |
19920 KB |
Output is correct |
8 |
Correct |
46 ms |
20272 KB |
Output is correct |
9 |
Correct |
23 ms |
15552 KB |
Output is correct |
10 |
Correct |
17 ms |
14832 KB |
Output is correct |
11 |
Correct |
20 ms |
13780 KB |
Output is correct |
12 |
Correct |
20 ms |
14884 KB |
Output is correct |
13 |
Correct |
24 ms |
15604 KB |
Output is correct |
14 |
Correct |
31 ms |
19380 KB |
Output is correct |
15 |
Correct |
18 ms |
14544 KB |
Output is correct |
16 |
Correct |
29 ms |
18764 KB |
Output is correct |
17 |
Correct |
20 ms |
14680 KB |
Output is correct |
18 |
Correct |
31 ms |
15768 KB |
Output is correct |
19 |
Correct |
2 ms |
8284 KB |
Output is correct |
20 |
Correct |
2 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
8284 KB |
Output is correct |
22 |
Correct |
3 ms |
8284 KB |
Output is correct |
23 |
Correct |
2 ms |
8284 KB |
Output is correct |
24 |
Correct |
2 ms |
8284 KB |
Output is correct |
25 |
Correct |
2 ms |
8284 KB |
Output is correct |
26 |
Correct |
2 ms |
8284 KB |
Output is correct |
27 |
Correct |
2 ms |
8284 KB |
Output is correct |
28 |
Correct |
2 ms |
8284 KB |
Output is correct |
29 |
Correct |
2 ms |
8284 KB |
Output is correct |
30 |
Correct |
2 ms |
8280 KB |
Output is correct |
31 |
Correct |
2 ms |
8284 KB |
Output is correct |
32 |
Correct |
2 ms |
8284 KB |
Output is correct |
33 |
Correct |
2 ms |
8284 KB |
Output is correct |