Submission #558865

# Submission time Handle Problem Language Result Execution time Memory
558865 2022-05-08T19:44:08 Z Olympia Brunhilda’s Birthday (BOI13_brunhilda) C++17
0 / 100
143 ms 262144 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 = 10000001;
    int res[mx];
    vector<int> fact[mx];
    for (int i = 0; i < p.size(); i++) {
        for (int j = p[i]; j < mx; j += p[i]) {
            fact[j].push_back(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 = 0; j < (int)invalid.size() - 1; j++) {
            if (invalid[j] + 1 <= invalid[j + 1] - 1) {
                ans = min(ans, st.query(invalid[j] + 1, invalid[j + 1] - 1) + 1);
            }
        }
        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';
        }
    }
}

Compilation message

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i = 0; i < p.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 109 ms 262144 KB Execution killed with signal 9
2 Runtime error 113 ms 262144 KB Execution killed with signal 9
3 Runtime error 115 ms 262144 KB Execution killed with signal 9
4 Runtime error 107 ms 262144 KB Execution killed with signal 9
5 Runtime error 108 ms 262144 KB Execution killed with signal 9
6 Runtime error 108 ms 262144 KB Execution killed with signal 9
7 Runtime error 117 ms 262144 KB Execution killed with signal 9
8 Runtime error 101 ms 262144 KB Execution killed with signal 9
9 Runtime error 105 ms 262144 KB Execution killed with signal 9
10 Runtime error 112 ms 262144 KB Execution killed with signal 9
11 Runtime error 108 ms 262144 KB Execution killed with signal 9
12 Runtime error 99 ms 262144 KB Execution killed with signal 9
13 Runtime error 114 ms 262144 KB Execution killed with signal 9
14 Runtime error 109 ms 262144 KB Execution killed with signal 9
15 Runtime error 101 ms 262144 KB Execution killed with signal 9
16 Runtime error 99 ms 262144 KB Execution killed with signal 9
17 Runtime error 107 ms 262144 KB Execution killed with signal 9
18 Runtime error 108 ms 262144 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 104 ms 262144 KB Execution killed with signal 9
2 Runtime error 131 ms 262144 KB Execution killed with signal 9
3 Runtime error 141 ms 262144 KB Execution killed with signal 9
4 Runtime error 105 ms 262144 KB Execution killed with signal 9
5 Runtime error 108 ms 262144 KB Execution killed with signal 9
6 Runtime error 109 ms 262144 KB Execution killed with signal 9
7 Runtime error 115 ms 262144 KB Execution killed with signal 9
8 Runtime error 103 ms 262144 KB Execution killed with signal 9
9 Runtime error 123 ms 262144 KB Execution killed with signal 9
10 Runtime error 135 ms 262144 KB Execution killed with signal 9
11 Runtime error 120 ms 262144 KB Execution killed with signal 9
12 Runtime error 103 ms 262144 KB Execution killed with signal 9
13 Runtime error 100 ms 262144 KB Execution killed with signal 9
14 Runtime error 107 ms 262144 KB Execution killed with signal 9
15 Runtime error 129 ms 262144 KB Execution killed with signal 9
16 Runtime error 121 ms 262144 KB Execution killed with signal 9
17 Runtime error 97 ms 262144 KB Execution killed with signal 9
18 Runtime error 127 ms 262144 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 117 ms 262144 KB Execution killed with signal 9
2 Runtime error 121 ms 262144 KB Execution killed with signal 9
3 Runtime error 109 ms 262144 KB Execution killed with signal 9
4 Runtime error 96 ms 262144 KB Execution killed with signal 9
5 Runtime error 131 ms 262144 KB Execution killed with signal 9
6 Runtime error 107 ms 262144 KB Execution killed with signal 9
7 Runtime error 133 ms 262144 KB Execution killed with signal 9
8 Runtime error 117 ms 262144 KB Execution killed with signal 9
9 Runtime error 113 ms 262144 KB Execution killed with signal 9
10 Runtime error 98 ms 262144 KB Execution killed with signal 9
11 Runtime error 100 ms 262144 KB Execution killed with signal 9
12 Runtime error 102 ms 262144 KB Execution killed with signal 9
13 Runtime error 103 ms 262144 KB Execution killed with signal 9
14 Runtime error 100 ms 262144 KB Execution killed with signal 9
15 Runtime error 98 ms 262144 KB Execution killed with signal 9
16 Runtime error 104 ms 262144 KB Execution killed with signal 9
17 Runtime error 111 ms 262144 KB Execution killed with signal 9
18 Runtime error 118 ms 262144 KB Execution killed with signal 9
19 Runtime error 99 ms 262144 KB Execution killed with signal 9
20 Runtime error 113 ms 262144 KB Execution killed with signal 9
21 Runtime error 101 ms 262144 KB Execution killed with signal 9
22 Runtime error 128 ms 262144 KB Execution killed with signal 9
23 Runtime error 107 ms 262144 KB Execution killed with signal 9
24 Runtime error 98 ms 262144 KB Execution killed with signal 9
25 Runtime error 111 ms 262144 KB Execution killed with signal 9
26 Runtime error 99 ms 262144 KB Execution killed with signal 9
27 Runtime error 130 ms 262144 KB Execution killed with signal 9
28 Runtime error 99 ms 262144 KB Execution killed with signal 9
29 Runtime error 130 ms 262144 KB Execution killed with signal 9
30 Runtime error 117 ms 262144 KB Execution killed with signal 9
31 Runtime error 100 ms 262144 KB Execution killed with signal 9
32 Runtime error 97 ms 262144 KB Execution killed with signal 9
33 Runtime error 97 ms 262144 KB Execution killed with signal 9
34 Runtime error 143 ms 262144 KB Execution killed with signal 9
35 Runtime error 97 ms 262144 KB Execution killed with signal 9
36 Runtime error 122 ms 262144 KB Execution killed with signal 9
37 Runtime error 129 ms 262144 KB Execution killed with signal 9
38 Runtime error 101 ms 262144 KB Execution killed with signal 9
39 Runtime error 100 ms 262144 KB Execution killed with signal 9
40 Runtime error 101 ms 262144 KB Execution killed with signal 9
41 Runtime error 130 ms 262144 KB Execution killed with signal 9
42 Runtime error 100 ms 262144 KB Execution killed with signal 9