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<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 998244353;
const int mxn = 2e5 + 5, mxq = 2e5 + 5, sq = 400, mxv = 2e7 + 5;
//const int base = (1 << 18);
const ll inf = 1e9, neg = -69420;
int n, k, r, cnt;
int cc[mxn + 1], a[mxn + 1], val[mxn + 1];
void add(int x){
cc[a[x]]++;
if(val[a[x]] && cc[a[x]] == val[a[x]])cnt++;
}
void rem(int x){
if(val[a[x]] && cc[a[x]] == val[a[x]])cnt--;
cc[a[x]]--;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k >> r;
for(int i = 1; i <= n; i++)cin >> a[i];
for(int i = 0; i < r; i++){
int id, v; cin >> id >> v; assert(v);
val[id] = max(val[id], v);
}
cnt = k - r;
int rp = 1, ans = inf;
for(int i = 1; i <= n; i++){
while(rp <= i)add(rp++);
if(i > 1){
rem(i - 1);
}else{
while(cnt != k && rp <= n){
add(rp++);
}
}
if(cnt == k)ans = min(ans, rp - i);
}
assert(ans > 0);
if(ans == inf){
assert(0);
cout << "impossible";
}else{
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... |