Submission #431723

# Submission time Handle Problem Language Result Execution time Memory
431723 2021-06-17T14:46:30 Z faresbasbs Fortune Telling 2 (JOI14_fortune_telling2) C++14
100 / 100
820 ms 41356 KB
#include <bits/stdc++.h>
using namespace std;
const int MXN = 700 * 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 18 ms 27724 KB Output is correct
2 Correct 18 ms 27780 KB Output is correct
3 Correct 18 ms 27724 KB Output is correct
4 Correct 21 ms 27784 KB Output is correct
5 Correct 20 ms 27772 KB Output is correct
6 Correct 19 ms 27828 KB Output is correct
7 Correct 18 ms 27724 KB Output is correct
8 Correct 19 ms 27724 KB Output is correct
9 Correct 18 ms 27740 KB Output is correct
10 Correct 18 ms 27724 KB Output is correct
11 Correct 18 ms 27776 KB Output is correct
12 Correct 18 ms 27744 KB Output is correct
13 Correct 19 ms 27724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27724 KB Output is correct
2 Correct 18 ms 27780 KB Output is correct
3 Correct 18 ms 27724 KB Output is correct
4 Correct 21 ms 27784 KB Output is correct
5 Correct 20 ms 27772 KB Output is correct
6 Correct 19 ms 27828 KB Output is correct
7 Correct 18 ms 27724 KB Output is correct
8 Correct 19 ms 27724 KB Output is correct
9 Correct 18 ms 27740 KB Output is correct
10 Correct 18 ms 27724 KB Output is correct
11 Correct 18 ms 27776 KB Output is correct
12 Correct 18 ms 27744 KB Output is correct
13 Correct 19 ms 27724 KB Output is correct
14 Correct 45 ms 28412 KB Output is correct
15 Correct 72 ms 29096 KB Output is correct
16 Correct 102 ms 29612 KB Output is correct
17 Correct 136 ms 30400 KB Output is correct
18 Correct 140 ms 30420 KB Output is correct
19 Correct 139 ms 30404 KB Output is correct
20 Correct 135 ms 30404 KB Output is correct
21 Correct 144 ms 30520 KB Output is correct
22 Correct 113 ms 29888 KB Output is correct
23 Correct 113 ms 29892 KB Output is correct
24 Correct 108 ms 29892 KB Output is correct
25 Correct 111 ms 30140 KB Output is correct
26 Correct 115 ms 30076 KB Output is correct
27 Correct 155 ms 30356 KB Output is correct
28 Correct 117 ms 30324 KB Output is correct
29 Correct 126 ms 30480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27724 KB Output is correct
2 Correct 18 ms 27780 KB Output is correct
3 Correct 18 ms 27724 KB Output is correct
4 Correct 21 ms 27784 KB Output is correct
5 Correct 20 ms 27772 KB Output is correct
6 Correct 19 ms 27828 KB Output is correct
7 Correct 18 ms 27724 KB Output is correct
8 Correct 19 ms 27724 KB Output is correct
9 Correct 18 ms 27740 KB Output is correct
10 Correct 18 ms 27724 KB Output is correct
11 Correct 18 ms 27776 KB Output is correct
12 Correct 18 ms 27744 KB Output is correct
13 Correct 19 ms 27724 KB Output is correct
14 Correct 45 ms 28412 KB Output is correct
15 Correct 72 ms 29096 KB Output is correct
16 Correct 102 ms 29612 KB Output is correct
17 Correct 136 ms 30400 KB Output is correct
18 Correct 140 ms 30420 KB Output is correct
19 Correct 139 ms 30404 KB Output is correct
20 Correct 135 ms 30404 KB Output is correct
21 Correct 144 ms 30520 KB Output is correct
22 Correct 113 ms 29888 KB Output is correct
23 Correct 113 ms 29892 KB Output is correct
24 Correct 108 ms 29892 KB Output is correct
25 Correct 111 ms 30140 KB Output is correct
26 Correct 115 ms 30076 KB Output is correct
27 Correct 155 ms 30356 KB Output is correct
28 Correct 117 ms 30324 KB Output is correct
29 Correct 126 ms 30480 KB Output is correct
30 Correct 277 ms 31704 KB Output is correct
31 Correct 355 ms 33832 KB Output is correct
32 Correct 528 ms 35996 KB Output is correct
33 Correct 815 ms 41096 KB Output is correct
34 Correct 239 ms 31288 KB Output is correct
35 Correct 733 ms 41060 KB Output is correct
36 Correct 777 ms 40976 KB Output is correct
37 Correct 810 ms 40952 KB Output is correct
38 Correct 778 ms 41080 KB Output is correct
39 Correct 820 ms 40968 KB Output is correct
40 Correct 769 ms 41356 KB Output is correct
41 Correct 773 ms 40848 KB Output is correct
42 Correct 733 ms 40712 KB Output is correct
43 Correct 569 ms 40936 KB Output is correct
44 Correct 543 ms 40908 KB Output is correct
45 Correct 586 ms 40804 KB Output is correct
46 Correct 545 ms 39036 KB Output is correct
47 Correct 548 ms 38784 KB Output is correct
48 Correct 674 ms 40960 KB Output is correct
49 Correct 589 ms 41136 KB Output is correct