# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
932575 | imarn | Martian DNA (BOI18_dna) | C++14 | 0 ms | 0 KiB |
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<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define vp vector<pii>
using namespace std;
const int N=2e5+5;
unordered_map<ll,int>mp,up;
ll a[N];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,k,R;cin>>n>>k>>R;
for(int i=0;i<n;i++)cin>>a[i],mp[a[i]]=0;
for(int i=0;i<R;i++){
ll b,q;cin>>b>>q;up[b]=q;
}int cnt=0;int l=0,ans=1e9;
for(int i=0;i<n;i++){mp[a[i]]++;if(up.find(a[i])!=up.end()&&mp[a[i]]==up[a[i]])cnt++;
while(up.find(a[l])==up.end()||(cnt==R&&mp[a[l]]>up[a[l]]))mp[a[l]]--,l++;
}if(cnt==R)ans=min(ans,i-l+1);
if(ans==1e9)cout<<"impossible";
else cout<<ans;
}