# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
548614 |
2022-04-14T02:09:18 Z |
Olympia |
Martian DNA (BOI18_dna) |
C++17 |
|
1184 ms |
1048576 KB |
#include <cmath>
#include <iostream>
#include <set>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <iomanip>
#include <type_traits>
#include <string>
#include <queue>
#include <map>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
using namespace std;
template<class T> struct Seg { // comb(ID,b) = b
const T ID = 0; T comb(T a, T b) { return a+b; }
int n; vector<T> seg;
void init(int _n) { n = _n; seg.assign(2*n,ID); }
void pull(int p) { seg[p] = comb(seg[2*p],seg[2*p+1]); }
void upd(int p, T val) { // set val at position p
seg[p += n] = val; for (p /= 2; p; p /= 2) pull(p); }
T query(int l, int r) { // sum on interval [l, r]
T ra = ID, rb = ID;
for (l += n, r += n+1; l < r; l /= 2, r /= 2) {
if (l&1) ra = comb(ra,seg[l++]);
if (r&1) rb = comb(seg[--r],rb);
}
return comb(ra,rb);
}
};
vector<Seg<int>> st;
vector<int> arr;
vector<pair<int,int>> queries;
bool okay (int l, int r) {
int R = queries.size();
for (int i = 0; i < R; i++) {
if (st[i].query(l, r) < queries[i].second) {
return false;
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, K, R;
cin >> N >> K >> R;
st.resize(R);
for (int i = 0; i < R; i++) {
st[i].init(N + 1);
}
arr.resize(N);
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
queries.resize(R);
for (int i = 0; i < R; i++) {
cin >> queries[i].first >> queries[i].second;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < R; j++) {
if (arr[i] == queries[j].first) {
st[j].upd(i, 1);
}
}
}
int myMin = INT_MAX;
for (int i = 0; i < N; i++) {
if (!okay(i, N - 1)) {
break;
}
int l = i;
int r = N - 1;
while (l != r) {
int m = (l + r)/2;
if (okay(i, m)) {
r = m;
} else {
l = m + 1;
}
}
//cout << i << " " << l << '\n';
myMin = min(myMin, l - i + 1);
}
if (myMin == INT_MAX) {
cout << "impossible\n";
} else {
cout << myMin;
}
}
Compilation message
dna.cpp:14: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
14 | #pragma GCC optimization ("O3")
|
dna.cpp:15: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
15 | #pragma GCC optimization ("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
7 ms |
596 KB |
Output is correct |
3 |
Correct |
6 ms |
596 KB |
Output is correct |
4 |
Correct |
11 ms |
596 KB |
Output is correct |
5 |
Correct |
8 ms |
672 KB |
Output is correct |
6 |
Correct |
13 ms |
660 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
610 ms |
15592 KB |
Output is correct |
2 |
Correct |
273 ms |
3060 KB |
Output is correct |
3 |
Correct |
1184 ms |
17204 KB |
Output is correct |
4 |
Correct |
788 ms |
17280 KB |
Output is correct |
5 |
Correct |
904 ms |
17920 KB |
Output is correct |
6 |
Correct |
34 ms |
17108 KB |
Output is correct |
7 |
Correct |
24 ms |
17336 KB |
Output is correct |
8 |
Correct |
869 ms |
18032 KB |
Output is correct |
9 |
Correct |
926 ms |
17720 KB |
Output is correct |
10 |
Correct |
854 ms |
17228 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
596 KB |
Output is correct |
13 |
Correct |
6 ms |
592 KB |
Output is correct |
14 |
Correct |
11 ms |
668 KB |
Output is correct |
15 |
Correct |
8 ms |
664 KB |
Output is correct |
16 |
Correct |
13 ms |
656 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
432 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |