This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |