///huynhocute123///
#include<bits/stdc++.h>
using namespace std;
#define S second
#define F first
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define pb push_back
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = b; i >= a; --i)
#define ALL(v) v.begin(),v.end()
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
//random_device rd;
//mt19937 rng(rd());
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
//#define int long long
const int maxN = 2 * 1e5 + 9 ;
const int modd = 1e9 + 7;
const int base = 2309;
const int MAX = 1e9+9;
const double pi = 3.14159265358979323846;
const double rad = 3.14159265358979323846 /180;
void minimize(int &u, int v){
if(v < u) u = v;
}
void maximize(int &u, int v){
if(v > u) u = v;
}
int n, k, t, m, res, a[maxN], mn[maxN], cnt[maxN];
int l, r;
bool vis[maxN];
vector<int> e[maxN];
void solve(){
cin >> n >> k >> m;
FOR(i, 1, n)cin >> a[i];
FOR(i, 1, m){
cin >> l >> r;
mn[l] =r;
}
int ck = 0;
FOR(i , 0 , k -1){
if(mn[i] == 0){
++ck;
}
}
// cout << ck << " ";
int r = 0;
res =MAX;
FOR(i , 1, n){
while(r <= n && ck != k){
r++;
if(r > n)break;
++cnt[a[r]];
if(cnt[a[r]] == mn[a[r]])++ck;
}
if(r > n)break;
if(k == ck)minimize(res,r- i +1);
if(mn[a[l]] == cnt[a[l]])--ck;
cnt[a[l]]--;
}
if(res == MAX)cout << "impossible";
else cout << res;
}
signed main(){
// freopen("name.inp","r",stdin);
// freopen("name.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
inp("task.inp");
int tc = 1;
// cin >> tc;
while( tc-- )solve();
cerr << '\n' << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s\n" ;
}
Compilation message
dna.cpp: In function 'int main()':
dna.cpp:12:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~
dna.cpp:74:5: note: in expansion of macro 'inp'
74 | inp("task.inp");
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
7504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
7580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |