답안 #558889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558889 2022-05-08T23:19:42 Z Olympia Brunhilda’s Birthday (BOI13_brunhilda) C++17
0 / 100
844 ms 134792 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 = 1000000;
    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 = 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);
                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';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 121 ms 33960 KB Output isn't correct
2 Incorrect 238 ms 51412 KB Output isn't correct
3 Incorrect 153 ms 48244 KB Output isn't correct
4 Incorrect 119 ms 30992 KB Output isn't correct
5 Incorrect 139 ms 36880 KB Output isn't correct
6 Incorrect 97 ms 33876 KB Output isn't correct
7 Incorrect 149 ms 48148 KB Output isn't correct
8 Incorrect 220 ms 52160 KB Output isn't correct
9 Incorrect 269 ms 54496 KB Output isn't correct
10 Incorrect 270 ms 55180 KB Output isn't correct
11 Incorrect 263 ms 50628 KB Output isn't correct
12 Incorrect 114 ms 30356 KB Output isn't correct
13 Incorrect 515 ms 58208 KB Output isn't correct
14 Incorrect 509 ms 58224 KB Output isn't correct
15 Incorrect 223 ms 50636 KB Output isn't correct
16 Incorrect 215 ms 51436 KB Output isn't correct
17 Incorrect 176 ms 36808 KB Output isn't correct
18 Incorrect 120 ms 31064 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 243 ms 69924 KB Execution killed with signal 11
2 Runtime error 289 ms 81872 KB Execution killed with signal 11
3 Runtime error 814 ms 130356 KB Execution killed with signal 11
4 Runtime error 266 ms 84796 KB Execution killed with signal 11
5 Runtime error 499 ms 116984 KB Execution killed with signal 11
6 Runtime error 253 ms 96272 KB Execution killed with signal 11
7 Runtime error 204 ms 69940 KB Execution killed with signal 11
8 Runtime error 276 ms 81612 KB Execution killed with signal 11
9 Runtime error 594 ms 123888 KB Execution killed with signal 11
10 Runtime error 774 ms 130352 KB Execution killed with signal 11
11 Runtime error 725 ms 124448 KB Execution killed with signal 11
12 Runtime error 388 ms 106852 KB Execution killed with signal 11
13 Runtime error 216 ms 73804 KB Execution killed with signal 11
14 Runtime error 264 ms 84756 KB Execution killed with signal 11
15 Runtime error 623 ms 122928 KB Execution killed with signal 11
16 Runtime error 281 ms 81840 KB Execution killed with signal 11
17 Runtime error 586 ms 117220 KB Execution killed with signal 11
18 Runtime error 664 ms 127812 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 678 ms 125128 KB Execution killed with signal 11
2 Runtime error 775 ms 127028 KB Execution killed with signal 11
3 Runtime error 795 ms 126788 KB Execution killed with signal 11
4 Runtime error 430 ms 108980 KB Execution killed with signal 11
5 Runtime error 360 ms 82356 KB Execution killed with signal 11
6 Runtime error 640 ms 115712 KB Execution killed with signal 11
7 Runtime error 523 ms 115876 KB Execution killed with signal 11
8 Runtime error 661 ms 125052 KB Execution killed with signal 11
9 Runtime error 735 ms 125188 KB Execution killed with signal 11
10 Runtime error 476 ms 104900 KB Execution killed with signal 11
11 Runtime error 359 ms 97508 KB Execution killed with signal 11
12 Runtime error 551 ms 114864 KB Execution killed with signal 11
13 Runtime error 745 ms 121836 KB Execution killed with signal 11
14 Runtime error 386 ms 113200 KB Execution killed with signal 11
15 Runtime error 633 ms 117684 KB Execution killed with signal 11
16 Runtime error 688 ms 118712 KB Execution killed with signal 11
17 Runtime error 617 ms 119084 KB Execution killed with signal 11
18 Runtime error 775 ms 126960 KB Execution killed with signal 11
19 Runtime error 277 ms 85196 KB Execution killed with signal 11
20 Runtime error 814 ms 126732 KB Execution killed with signal 11
21 Runtime error 382 ms 115900 KB Execution killed with signal 11
22 Runtime error 790 ms 133268 KB Execution killed with signal 11
23 Runtime error 291 ms 78628 KB Execution killed with signal 11
24 Runtime error 175 ms 69728 KB Execution killed with signal 11
25 Runtime error 441 ms 107392 KB Execution killed with signal 11
26 Runtime error 396 ms 108880 KB Execution killed with signal 11
27 Runtime error 844 ms 134792 KB Execution killed with signal 11
28 Runtime error 227 ms 80572 KB Execution killed with signal 11
29 Runtime error 601 ms 129536 KB Execution killed with signal 11
30 Runtime error 538 ms 124332 KB Execution killed with signal 11
31 Runtime error 257 ms 83036 KB Execution killed with signal 11
32 Runtime error 305 ms 89328 KB Execution killed with signal 11
33 Runtime error 168 ms 64992 KB Execution killed with signal 11
34 Runtime error 508 ms 115828 KB Execution killed with signal 11
35 Runtime error 243 ms 82064 KB Execution killed with signal 11
36 Runtime error 749 ms 131640 KB Execution killed with signal 11
37 Runtime error 308 ms 82496 KB Execution killed with signal 11
38 Runtime error 525 ms 115616 KB Execution killed with signal 11
39 Runtime error 203 ms 73476 KB Execution killed with signal 11
40 Runtime error 463 ms 113176 KB Execution killed with signal 11
41 Runtime error 514 ms 120384 KB Execution killed with signal 11
42 Runtime error 589 ms 118224 KB Execution killed with signal 11