Submission #405139

# Submission time Handle Problem Language Result Execution time Memory
405139 2021-05-15T18:25:15 Z saarang123 Fortune Telling 2 (JOI14_fortune_telling2) C++17
35 / 100
460 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;
const int MXN = 500 * 1000 + 3;
int tree[MXN << 2], a[MXN], b[MXN], t[MXN], oga[MXN], ogb[MXN];
vector<int> coord, q[MXN];
int n, k, sz;

function<int(int, int)> comb = [] (int x, int y) {
	return max(x, y);
};

void update(int v, int tl, int tr, int pos, int x) {
	if(tl == tr)
		tree[v] = comb(tree[v], x);
	else {
		int tm = (tl + tr) >> 1;
		if(pos <= tm)
			update(v << 1, tl, tm, pos, x);
		else
			update(v << 1|1, tm + 1, tr, pos, x);
		tree[v] = comb(tree[v << 1], tree[v << 1|1]);
	}
}

void upd(int pos, int x) {
	update(1, 1, MXN - 2, pos, x);
}

int query(int v, int tl, int tr, int l, int r) {
	if(l > r)
		return 0;
	if(l <= tl && tr <= r)
		return tree[v];
	int tm = (tl + tr) >> 1;
	return comb(query(v << 1, tl, tm, l, min(tm, r)),
				query(v << 1|1, tm + 1, tr, max(tm + 1, l), r));
}

int query(int l, int r) {
	return query(1, 1, MXN - 2, l, r);
}

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
    	cin >> oga[i] >> ogb[i];
    	coord.push_back(oga[i]);
    	coord.push_back(ogb[i]);
    }
    for(int i = 1; i <= k; i++) {
    	cin >> t[i];
    	coord.push_back(t[i]);
    }

    sort(coord.begin(), coord.end());
    coord.resize(unique(coord.begin(), coord.end()) - coord.begin());
    sz = coord.size();
    auto id = [&] (int x) {
    	return upper_bound(coord.begin(), coord.end(), x) - coord.begin();
    };
    for(int i = 1; i <= n; i++) {
    	a[i] = id(oga[i]);
    	b[i] = id(ogb[i]);
    }
    for(int i = 1; i <= k; i++) {
    	t[i] = id(t[i]);
    	upd(t[i], i);
    }

    for(int i = 1; i <= n; i++) {
    	int x = query(min(a[i], b[i]), max(a[i], b[i]) - 1);
    	q[x].push_back(i);
    }
    memset(tree, 0, sizeof tree);
    comb = [&] (int x, int y) {
    	return x + y;
    };
    long long ans = 0;
    for(int x = k; x >= 0; x--) {
    	for(int i : q[x]) {
    		int parity = query(max(a[i], b[i]), sz) & 1;
    		if(x)
    			parity ^= a[i] < b[i];
    		ans += parity ? ogb[i] : oga[i];
    	}
    	upd(t[x], 1);
    }

    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19916 KB Output is correct
2 Correct 13 ms 19848 KB Output is correct
3 Correct 14 ms 19936 KB Output is correct
4 Correct 14 ms 19904 KB Output is correct
5 Correct 14 ms 19984 KB Output is correct
6 Correct 14 ms 19868 KB Output is correct
7 Correct 16 ms 19916 KB Output is correct
8 Correct 13 ms 19916 KB Output is correct
9 Correct 13 ms 19980 KB Output is correct
10 Correct 13 ms 19972 KB Output is correct
11 Correct 13 ms 19920 KB Output is correct
12 Correct 14 ms 19916 KB Output is correct
13 Correct 13 ms 19908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19916 KB Output is correct
2 Correct 13 ms 19848 KB Output is correct
3 Correct 14 ms 19936 KB Output is correct
4 Correct 14 ms 19904 KB Output is correct
5 Correct 14 ms 19984 KB Output is correct
6 Correct 14 ms 19868 KB Output is correct
7 Correct 16 ms 19916 KB Output is correct
8 Correct 13 ms 19916 KB Output is correct
9 Correct 13 ms 19980 KB Output is correct
10 Correct 13 ms 19972 KB Output is correct
11 Correct 13 ms 19920 KB Output is correct
12 Correct 14 ms 19916 KB Output is correct
13 Correct 13 ms 19908 KB Output is correct
14 Correct 38 ms 20260 KB Output is correct
15 Correct 63 ms 20680 KB Output is correct
16 Correct 95 ms 20988 KB Output is correct
17 Correct 124 ms 21300 KB Output is correct
18 Correct 125 ms 21316 KB Output is correct
19 Correct 124 ms 21308 KB Output is correct
20 Correct 123 ms 21340 KB Output is correct
21 Correct 129 ms 21568 KB Output is correct
22 Correct 108 ms 21344 KB Output is correct
23 Correct 104 ms 21364 KB Output is correct
24 Correct 107 ms 21340 KB Output is correct
25 Correct 106 ms 21596 KB Output is correct
26 Correct 102 ms 21136 KB Output is correct
27 Correct 117 ms 21316 KB Output is correct
28 Correct 108 ms 21344 KB Output is correct
29 Correct 114 ms 21480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19916 KB Output is correct
2 Correct 13 ms 19848 KB Output is correct
3 Correct 14 ms 19936 KB Output is correct
4 Correct 14 ms 19904 KB Output is correct
5 Correct 14 ms 19984 KB Output is correct
6 Correct 14 ms 19868 KB Output is correct
7 Correct 16 ms 19916 KB Output is correct
8 Correct 13 ms 19916 KB Output is correct
9 Correct 13 ms 19980 KB Output is correct
10 Correct 13 ms 19972 KB Output is correct
11 Correct 13 ms 19920 KB Output is correct
12 Correct 14 ms 19916 KB Output is correct
13 Correct 13 ms 19908 KB Output is correct
14 Correct 38 ms 20260 KB Output is correct
15 Correct 63 ms 20680 KB Output is correct
16 Correct 95 ms 20988 KB Output is correct
17 Correct 124 ms 21300 KB Output is correct
18 Correct 125 ms 21316 KB Output is correct
19 Correct 124 ms 21308 KB Output is correct
20 Correct 123 ms 21340 KB Output is correct
21 Correct 129 ms 21568 KB Output is correct
22 Correct 108 ms 21344 KB Output is correct
23 Correct 104 ms 21364 KB Output is correct
24 Correct 107 ms 21340 KB Output is correct
25 Correct 106 ms 21596 KB Output is correct
26 Correct 102 ms 21136 KB Output is correct
27 Correct 117 ms 21316 KB Output is correct
28 Correct 108 ms 21344 KB Output is correct
29 Correct 114 ms 21480 KB Output is correct
30 Correct 238 ms 23904 KB Output is correct
31 Correct 326 ms 25880 KB Output is correct
32 Correct 437 ms 28300 KB Output is correct
33 Runtime error 460 ms 262148 KB Execution killed with signal 9
34 Halted 0 ms 0 KB -