#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <memory.h>
#include <set>
using namespace std;
#define rep(i, n) for(int i =0;i<(n);i++)
#define per(i, n) for (int i=((int)n-1);i>=0;i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define make_unique(x) { sort(all(x)); x.resize(unique(x.begin(), x.end()) - x.begin()); }
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(x) { cerr << #x << "= " << x << "\n"; }
typedef long long ll;
typedef vector<int>vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
int cnt[200100];
int cur[200100];
int satisfy = 0;
#pragma region
void add(int x) {
if (cur[x] >= cnt[x]) satisfy--;
cur[x]++;
if (cur[x] >= cnt[x]) satisfy++;
}
void del(int x) {
if (cur[x] >= cnt[x]) satisfy--;
cur[x]--;
if (cur[x] >= cnt[x]) satisfy++;
}
int main() {
int n, k, R;
cin >> n >> k >> R;
vi a(n);
rep(i, n) cin >> a[i];
rep(i, R) {
int b, q;
cin >> b >> q;
cnt[b] = q;
}
rep(i, n) if (cur[i] >= cnt[i]) satisfy++;
int r = 0;
const int inf = 1e9;
int len = inf;
rep(l, n) {
while (r < n && satisfy < n) {
add(a[r]);
r++;
}
if(satisfy == n) len = min(len, r - l);
del(a[l]);
}
if (len == inf) {
cout << "impossible\n";
}
else {
cout << len << "\n";
}
return 0;
}
Compilation message
dna.cpp:42: warning: ignoring #pragma region [-Wunknown-pragmas]
42 | #pragma region
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
1516 KB |
Output is correct |
2 |
Correct |
38 ms |
1516 KB |
Output is correct |
3 |
Correct |
38 ms |
1516 KB |
Output is correct |
4 |
Correct |
37 ms |
1516 KB |
Output is correct |
5 |
Correct |
62 ms |
2668 KB |
Output is correct |
6 |
Correct |
36 ms |
1516 KB |
Output is correct |
7 |
Correct |
40 ms |
1644 KB |
Output is correct |
8 |
Correct |
93 ms |
3180 KB |
Output is correct |
9 |
Correct |
54 ms |
2156 KB |
Output is correct |
10 |
Correct |
50 ms |
1516 KB |
Output is correct |
11 |
Correct |
3 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
3436 KB |
Output is correct |
2 |
Correct |
94 ms |
3180 KB |
Output is correct |
3 |
Correct |
74 ms |
2924 KB |
Output is correct |
4 |
Correct |
37 ms |
1516 KB |
Output is correct |
5 |
Correct |
119 ms |
4076 KB |
Output is correct |
6 |
Correct |
119 ms |
4588 KB |
Output is correct |
7 |
Correct |
58 ms |
2156 KB |
Output is correct |
8 |
Correct |
71 ms |
2412 KB |
Output is correct |
9 |
Correct |
36 ms |
1516 KB |
Output is correct |
10 |
Correct |
49 ms |
1516 KB |
Output is correct |
11 |
Correct |
38 ms |
1516 KB |
Output is correct |
12 |
Correct |
39 ms |
1516 KB |
Output is correct |
13 |
Correct |
71 ms |
2540 KB |
Output is correct |
14 |
Correct |
35 ms |
1516 KB |
Output is correct |
15 |
Correct |
41 ms |
1644 KB |
Output is correct |
16 |
Correct |
66 ms |
3180 KB |
Output is correct |
17 |
Correct |
55 ms |
2156 KB |
Output is correct |
18 |
Correct |
35 ms |
1516 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
364 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |