This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//!yrt tsuj uoy srettam gnihton no emoc
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
const int maxn = 2e5 + 5;
int a[maxn], t[maxn], l[maxn], ind[maxn];
int b[maxn], q[maxn], f[maxn], nxt[maxn];
int main(){
fast_io;
int n, k, r;
cin >> n >> k >> r;
for(int i = 0; i < n; i ++){
cin >> a[i];
ind[a[i]] = l[a[i]] = -1;
}
for(int i = 0; i < r; i ++){
cin >> b[i] >> q[i];
ind[b[i]] = i;
}
int ans = INT_MAX;
set <int> s, cor;
for(int i = 0; i < n; i ++){
t[a[i]] ++;
if(ind[a[i]] != -1){
if(l[a[i]] == -1){
f[a[i]] = i;
}
if(l[a[i]] != -1){
nxt[l[a[i]]] = i;
}
l[a[i]] = i;
s.insert(i);
if(t[a[i]] >= q[ind[a[i]]]){
cor.insert(a[i]);
}
if(t[a[i]] > q[ind[a[i]]]){
t[a[i]] --;
s.erase(f[a[i]]);
f[a[i]] = nxt[f[a[i]]];
}
}
// cout << i << " -> " << *s.begin() << endl;
if((int)cor.size() >= r){
// cout << i << " :: " << *s.begin() << endl;
ans = min(ans, i - *s.begin() + 1);
}
}
if(ans == INT_MAX){
cout << "impossible";
return 0;
}
cout << ans;
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... |