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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const int N = 1000007;
ll n, m, k;
ll a[N];
ll cc[N];
set<int>cur;
ll cnt[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for(int i=0;i<k;i++){
int x,y;
cin>>x>>y;
cc[x]=y;
cur.insert(x);
}
int l=0,r=0;
int ans=MOD;
while(l<n&&r<=n){
if(!cur.empty()){
if(r==n)break;
cnt[a[r]]++;
if(cnt[a[r]]==cc[a[r]]){
cur.erase(a[r]);
}
r++;
}
else{
ans=min(ans,r-l);
cnt[a[l]]--;
if(cnt[a[l]]==cc[a[l]]-1){
cur.insert(a[l]);
}
l++;
}
// for(auto x:cur)cout<<x<<" ";
// cout<<endl;
}
if(ans!=MOD)cout<<ans<<endl;
else cout<<"impossible"<<endl;
return 0;
}
# | 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... |