#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(I, L, R) for(int I(L) ; I <= (int)R ; ++I)
#define FOD(I, R, L) for(int I(R) ; I >= (int)L ; --I)
#define FOA(I, A) for(auto &I : A)
#define print(A,L,R) FOR(OK, L, R){if(A[OK]<=-oo / 10||A[OK]>=oo / 10)cout<<"- ";else cout<<A[OK]<<' ';}cout<<'\n';
#define prints(A) FOA(OK, A){cout<<OK<<' ';}cout << '\n';
#define printz(A,L,R) FOR(OK, 1, L){FOR(KO, 1, R){if(A[OK][KO]>-oo / 10&&A[OK][KO]<oo)cout<<A[OK][KO]<<' ';else cout << "- ";} cout << '\n';}cout << '\n';
#define fs first
#define sd second
#define ii pair<int,int>
#define iii pair<int, ii>
#define all(A) A.begin(), A.end()
#define quickly ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILE "PAIR"
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int oo = 1e18;
struct Modint{
int x;
Modint(){x = 0;}
Modint(int _x){ x = (_x % mod + mod) % mod; }
inline Modint operator + (const Modint &other) const{ return (x + other.x) % mod; }
inline Modint operator - (const Modint &other) const{ return (x - other.x + mod) % mod; }
inline Modint operator * (const Modint &other) const{ return (1LL * x * other.x) % mod; }
inline void operator += (const Modint &other){ *this = *this + other; }
inline void operator -= (const Modint &other){ *this = *this - other; }
inline void operator *= (const Modint &other){ *this = *this * other; }
friend ostream& operator << (ostream& os, const Modint &t){ return os << t.x; }
};
int n, k, q, is;
int a[N], cnt[N], re[N];
void add(int x){
cnt[x]++;
if(cnt[x] == re[x]){
is++;
}
}
void del(int x){
if(cnt[x] == re[x]){
is--;
}
cnt[x]--;
}
signed main(){ quickly
if(fopen(FILE".inp", "r")){
freopen(FILE".inp", "r", stdin);
freopen(FILE".out", "w", stdout);
}
cin >> n >> k >> q;
FOR(i, 1, n){
cin >> a[i];
}
FOR(i, 1, q){
int x, y;
cin >> x >> y;
re[x] = max(re[x], y);
}
FOR(i, 0, k - 1) is += (re[i] == 0);
int l = 1, ans = oo;
FOR(r, 1, n){
add(a[r]);
while(l <= r && is == k){
ans = min(ans, r - l + 1);
del(a[l]);
++l;
}
}
if(ans == oo){
cout << "impossible";
return 0;
}
cout << ans;
}
Compilation message (stderr)
dna.cpp: In function 'int main()':
dna.cpp:63:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen(FILE".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dna.cpp:64:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | freopen(FILE".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |