# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
558888 | 2022-05-08T23:19:01 Z | Olympia | Brunhilda’s Birthday (BOI13_brunhilda) | C++17 | 57 ms | 13548 KB |
#include <bits/stdc++.h> using namespace std; template<class T> struct Seg { // comb(ID,b) = b const T ID = 1e9; T comb(T a, T b) { return min(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) { // min 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); } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int M, Q; cin >> M >> Q; vector<int> p(M); Seg<int> st; st.init(M + 1); map<int,int> primes; for (int i = 0; i < M; i++) { cin >> p[i]; st.upd(i, 0); } sort(p.begin(), p.end()); for (int i = 0; i < M; i++) { primes[p[i]] = i; st.upd(i, 0); } int mx = 10000; int res[mx]; bool isPrime[mx]; for (int i = 0; i < mx; i++) { isPrime[i] = true; } isPrime[0] = isPrime[1] = false; vector<int> fact[mx]; for (int i = 2; i < mx; i++) { if (isPrime[i]) { for (int j = 2 * i; j < mx; j += i) { isPrime[j] = false; if (primes.count(i)) fact[j].push_back(primes[i]); } if (primes.count(i)) fact[i].push_back(primes[i]); } } for (int i = 1; i < mx; i++) { int ans = 1e9; vector<int> invalid; invalid.push_back(-1); for (int j: fact[i]) { invalid.push_back(j); } invalid.push_back(p.size()); for (int j = (int)invalid.size() - 2; j >= 0; j--) { if (invalid[j] + 1 <= invalid[j + 1] - 1) { ans = min(ans, st.query(invalid[j] + 1, invalid[j + 1] - 1) + 1); break; } } for (int j: invalid) { if (j >= 0 && j < (int)p.size()) { st.upd(j, ans); } } res[i] = ans; } while (Q--) { int x; cin >> x; if (res[x] == (int)1e9) { cout << "oo\n"; } else { cout << res[x] << '\n'; } } }
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 596 KB | Output isn't correct |
2 | Incorrect | 3 ms | 724 KB | Output isn't correct |
3 | Incorrect | 2 ms | 724 KB | Output isn't correct |
4 | Incorrect | 3 ms | 596 KB | Output isn't correct |
5 | Correct | 3 ms | 596 KB | Output is correct |
6 | Incorrect | 2 ms | 596 KB | Output isn't correct |
7 | Incorrect | 2 ms | 724 KB | Output isn't correct |
8 | Incorrect | 2 ms | 724 KB | Output isn't correct |
9 | Correct | 2 ms | 852 KB | Output is correct |
10 | Incorrect | 3 ms | 852 KB | Output isn't correct |
11 | Incorrect | 2 ms | 724 KB | Output isn't correct |
12 | Correct | 1 ms | 596 KB | Output is correct |
13 | Correct | 4 ms | 852 KB | Output is correct |
14 | Correct | 6 ms | 980 KB | Output is correct |
15 | Incorrect | 2 ms | 724 KB | Output isn't correct |
16 | Incorrect | 3 ms | 724 KB | Output isn't correct |
17 | Incorrect | 3 ms | 724 KB | Output isn't correct |
18 | Incorrect | 4 ms | 596 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 7 ms | 2516 KB | Execution killed with signal 11 |
2 | Runtime error | 46 ms | 11984 KB | Execution killed with signal 11 |
3 | Runtime error | 33 ms | 9932 KB | Execution killed with signal 11 |
4 | Runtime error | 4 ms | 1620 KB | Execution killed with signal 11 |
5 | Runtime error | 25 ms | 7636 KB | Execution killed with signal 11 |
6 | Runtime error | 3 ms | 1492 KB | Execution killed with signal 11 |
7 | Runtime error | 8 ms | 2516 KB | Execution killed with signal 11 |
8 | Runtime error | 3 ms | 1364 KB | Execution killed with signal 11 |
9 | Runtime error | 33 ms | 9960 KB | Execution killed with signal 11 |
10 | Runtime error | 33 ms | 9880 KB | Execution killed with signal 11 |
11 | Runtime error | 21 ms | 6356 KB | Execution killed with signal 11 |
12 | Runtime error | 6 ms | 1748 KB | Execution killed with signal 11 |
13 | Runtime error | 4 ms | 1492 KB | Execution killed with signal 11 |
14 | Runtime error | 5 ms | 1620 KB | Execution killed with signal 11 |
15 | Runtime error | 27 ms | 6604 KB | Execution killed with signal 11 |
16 | Runtime error | 37 ms | 11920 KB | Execution killed with signal 11 |
17 | Runtime error | 6 ms | 1896 KB | Execution killed with signal 11 |
18 | Runtime error | 42 ms | 13408 KB | Execution killed with signal 11 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 23 ms | 7608 KB | Execution killed with signal 11 |
2 | Runtime error | 24 ms | 7912 KB | Execution killed with signal 11 |
3 | Runtime error | 25 ms | 7572 KB | Execution killed with signal 11 |
4 | Runtime error | 7 ms | 1876 KB | Execution killed with signal 11 |
5 | Runtime error | 57 ms | 12740 KB | Execution killed with signal 11 |
6 | Runtime error | 10 ms | 2516 KB | Execution killed with signal 11 |
7 | Runtime error | 47 ms | 13224 KB | Execution killed with signal 11 |
8 | Runtime error | 25 ms | 7508 KB | Execution killed with signal 11 |
9 | Runtime error | 24 ms | 7584 KB | Execution killed with signal 11 |
10 | Runtime error | 6 ms | 2124 KB | Execution killed with signal 11 |
11 | Runtime error | 5 ms | 1860 KB | Execution killed with signal 11 |
12 | Runtime error | 6 ms | 2260 KB | Execution killed with signal 11 |
13 | Runtime error | 15 ms | 5204 KB | Execution killed with signal 11 |
14 | Runtime error | 3 ms | 1492 KB | Execution killed with signal 11 |
15 | Runtime error | 7 ms | 2260 KB | Execution killed with signal 11 |
16 | Runtime error | 11 ms | 2404 KB | Execution killed with signal 11 |
17 | Runtime error | 23 ms | 6836 KB | Execution killed with signal 11 |
18 | Runtime error | 33 ms | 7812 KB | Execution killed with signal 11 |
19 | Runtime error | 5 ms | 1796 KB | Execution killed with signal 11 |
20 | Runtime error | 24 ms | 7568 KB | Execution killed with signal 11 |
21 | Runtime error | 4 ms | 1492 KB | Execution killed with signal 11 |
22 | Runtime error | 44 ms | 13536 KB | Execution killed with signal 11 |
23 | Runtime error | 12 ms | 4564 KB | Execution killed with signal 11 |
24 | Runtime error | 3 ms | 1236 KB | Execution killed with signal 11 |
25 | Runtime error | 4 ms | 1876 KB | Execution killed with signal 11 |
26 | Runtime error | 5 ms | 1876 KB | Execution killed with signal 11 |
27 | Runtime error | 45 ms | 13548 KB | Execution killed with signal 11 |
28 | Runtime error | 3 ms | 1236 KB | Execution killed with signal 11 |
29 | Runtime error | 52 ms | 13412 KB | Execution killed with signal 11 |
30 | Runtime error | 35 ms | 9852 KB | Execution killed with signal 11 |
31 | Runtime error | 4 ms | 1748 KB | Execution killed with signal 11 |
32 | Runtime error | 4 ms | 1620 KB | Execution killed with signal 11 |
33 | Runtime error | 2 ms | 1236 KB | Execution killed with signal 11 |
34 | Runtime error | 44 ms | 13284 KB | Execution killed with signal 11 |
35 | Runtime error | 3 ms | 1492 KB | Execution killed with signal 11 |
36 | Runtime error | 41 ms | 12264 KB | Execution killed with signal 11 |
37 | Runtime error | 42 ms | 12752 KB | Execution killed with signal 11 |
38 | Runtime error | 7 ms | 2516 KB | Execution killed with signal 11 |
39 | Runtime error | 3 ms | 1364 KB | Execution killed with signal 11 |
40 | Runtime error | 8 ms | 2644 KB | Execution killed with signal 11 |
41 | Runtime error | 45 ms | 13404 KB | Execution killed with signal 11 |
42 | Runtime error | 6 ms | 1988 KB | Execution killed with signal 11 |