이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=1e6+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=1e6+17;
const int L=20;
int t[N],lim[N],il[N],g[N];
ull pot[N];
void solve(){
int n,k,m;
cin>>n>>k>>m;
for(int i=1;i<=n;i++) cin>>t[i];
pot[0]=1;
for(int i=1;i<=m;i++) pot[i]=pot[i-1]*p2;
for(int i=0;i<k;i++) lim[i]=INFi;
for(int a,b,i=1;i<=m;i++){
cin>>a>>b;
lim[a]=b,g[a]=i;
}
int res=-1,wsk=1;
ull curr=0,total=0;
for(int i=1;i<=m;i++) total+=pot[i];
for(int i=1;i<=n;i++){
wsk=max(wsk,i);
while(wsk<=n and curr!=total){
il[t[wsk]]++;
if(lim[t[wsk]]==il[t[wsk]]) curr+=pot[g[t[wsk]]];
wsk++;
}
if(total==curr) res=(res==-1?wsk-i:min(res,wsk-i));
il[t[i]]--;
if(lim[t[i]]==il[t[i]]+1) curr-=pot[g[t[i]]];
}
if(res==-1) cout<<"impossible\n";
else cout<<res<<"\n";
}
int main(){
int tt=1;
//cin>>tt;
while(tt--) solve();
}
# | 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... |