Submission #451953

#TimeUsernameProblemLanguageResultExecution timeMemory
451953Sarah_Mokhtar Martian DNA (BOI18_dna)C++14
100 / 100
79 ms4684 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define read freopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #define LESSGO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); const ll N=3e5+10,M=505,OO=1e16,mod=1e9+7; int n,k,q,req[N],a[N]; bool ok(int x){ int cnt[N]={0},vis[N]={0}; int valid=0; for(int i=0;i<x;++i){ if(!req[a[i]]) continue; cnt[a[i]]++; if(cnt[a[i]]>=req[a[i]]&&!vis[a[i]]){ vis[a[i]]=1; ++valid; } } if(valid==q) return 1; for(int i=0,j=x;j<n;++i,++j){ cnt[a[i]]--; cnt[a[j]]++; if(req[a[i]]&&cnt[a[i]]<req[a[i]]&&vis[a[i]]){ vis[a[i]]=0; --valid; } if(req[a[j]]&&cnt[a[j]]>=req[a[j]]&&!vis[a[j]]){ ++valid; vis[a[j]]=1; } if(valid==q) return 1; } return 0; } int bs(){ int low=0,high=n,med; while(low<high){ med=(low+high)>>1; if(ok(med)) high=med; else low=med+1; } return low; } int main(){ LESSGO; cin>>n>>k>>q; for(int i=0;i<n;++i) cin>>a[i]; for(int i=0;i<q;++i){ int x,y; cin>>x>>y; req[x]=y; } int len=bs(); if(ok(len)) cout<<len<<'\n'; else cout<<"impossible\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...