# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
927126 |
2024-02-14T09:53:56 Z |
vjudge1 |
Martian DNA (BOI18_dna) |
C++17 |
|
59 ms |
14928 KB |
#pragma GCC optimize("O3", "unroll-loops") // "Ofast"
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt")
#include <bits/stdc++.h>
#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
#define dbg(x) cerr << #x << " = " << x << '\n'
#define bit(x, i) ((x) >> (i) & 1)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int N = 1e6 + 5, mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const ld eps = 1e-6;
ll add (ll a, ll b) {
a += b;
if (a < 0) a += mod;
if (a >= mod) a -= mod;
return a;
}
ll mul (ll a, ll b) {
a *= b;
if (a >= mod) a %= mod;
return a;
}
int n, k, R, a[N], b[N], cnt[N], t[4 * N];
void build (int v = 1, int tl = 0, int tr = k) {
if (tl == tr) {
t[v] = b[tl];
return;
}
int tm = tl + tr >> 1;
build(v << 1, tl, tm); build(v << 1 | 1, tm + 1, tr);
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
void upd (int pos, int x, int v = 1, int tl = 0, int tr = k) {
if (tl == tr) {
t[v] += x;
return;
}
int tm = tl + tr >> 1;
if (pos <= tm) upd(pos, x, v << 1, tl, tm);
else upd(pos, x, v << 1 | 1, tm + 1, tr);
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
void solve () {
cin >> n >> k >> R;
for (int i = 1; i <= n; i++) cin >> a[i], cnt[a[i]]++;
int K = 0;
for (int i = 1; i <= R; i++) {
int x, y;
cin >> x >> y;
b[x] = y;
K += y;
}
for (int i = 0; i < k; i++) {
if (cnt[i] < b[i]) cout << "impossible\n", exit(0);
}
build();
int l = 1, r = 1, ans = inf;
while (l <= r && r <= n) {
while (r <= n && t[1] > 0) upd(a[r], -1), r++;
if (t[1] == 0) ans = min(ans, r - l);
upd(a[l], 1), l++;
}
cout << ans;
cout << '\n';
}
bool testcases = 0;
signed main() {
#ifdef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
cin.tie(0) -> sync_with_stdio(0);
int test = 1;
if (testcases) cin >> test;
for (int cs = 1; cs <= test; cs++) {
solve();
}
}
Compilation message
dna.cpp: In function 'void build(long long int, long long int, long long int)':
dna.cpp:45:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
45 | int tm = tl + tr >> 1;
| ~~~^~~~
dna.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int)':
dna.cpp:55:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int tm = tl + tr >> 1;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6744 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8536 KB |
Output is correct |
2 |
Correct |
11 ms |
8540 KB |
Output is correct |
3 |
Correct |
13 ms |
8540 KB |
Output is correct |
4 |
Correct |
12 ms |
8540 KB |
Output is correct |
5 |
Correct |
43 ms |
10844 KB |
Output is correct |
6 |
Correct |
12 ms |
8540 KB |
Output is correct |
7 |
Correct |
11 ms |
8536 KB |
Output is correct |
8 |
Correct |
51 ms |
12852 KB |
Output is correct |
9 |
Correct |
35 ms |
10840 KB |
Output is correct |
10 |
Correct |
14 ms |
8536 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
2 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
8536 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
12888 KB |
Output is correct |
2 |
Correct |
47 ms |
12892 KB |
Output is correct |
3 |
Correct |
46 ms |
12892 KB |
Output is correct |
4 |
Correct |
10 ms |
8536 KB |
Output is correct |
5 |
Correct |
22 ms |
10588 KB |
Output is correct |
6 |
Correct |
59 ms |
14928 KB |
Output is correct |
7 |
Correct |
28 ms |
10844 KB |
Output is correct |
8 |
Correct |
38 ms |
12892 KB |
Output is correct |
9 |
Correct |
11 ms |
8536 KB |
Output is correct |
10 |
Correct |
10 ms |
8540 KB |
Output is correct |
11 |
Correct |
13 ms |
8672 KB |
Output is correct |
12 |
Correct |
12 ms |
8540 KB |
Output is correct |
13 |
Correct |
44 ms |
10904 KB |
Output is correct |
14 |
Correct |
12 ms |
8540 KB |
Output is correct |
15 |
Correct |
10 ms |
8540 KB |
Output is correct |
16 |
Correct |
49 ms |
12892 KB |
Output is correct |
17 |
Correct |
36 ms |
10840 KB |
Output is correct |
18 |
Correct |
15 ms |
8536 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |