Submission #256056

# Submission time Handle Problem Language Result Execution time Memory
256056 2020-08-02T09:16:11 Z islingr Fortune Telling 2 (JOI14_fortune_telling2) C++17
100 / 100
230 ms 12024 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)

const int N = 1 << 18, inf = 2e9;
int mn[N << 1];
bool s[N << 1];

int q, p, x;
void upd(int v, int l, int r) {
	if (r - l == 1) return mn[v] = x, void(s[v] = 1);
	int m = (l + r) >> 1;
	if (p < m) upd(v << 1, l, m);
	else upd(v << 1|1, m, r);
	mn[v] = min(mn[v << 1], mn[v << 1|1]);
	s[v] = s[v << 1] ^ s[v << 1|1];
}
void upd(int a, int b) { p = a; x = b; upd(1, 0, q); }

int find(int v, int l, int r) {
	if (x <= mn[v]) return 0;
	if (r - l == 1) return r;
	int m = (l + r) >> 1;
	int res = find(v << 1|1, m, r);
	if (res) return res;
	return find(v << 1, l, m);
}
int find(int a) { x = a; return find(1, 0, q); }

int lo, hi;
bool sum(int v, int l, int r) {
	if (hi <= l || r <= lo) return 0;
	if (lo <= l && r <= hi) return s[v];
	int m = (l + r) >> 1;
	return sum(v << 1, l, m) ^ sum(v << 1|1, m, r);
}
bool sum(int l, int r) { lo = l; hi = r; return sum(1, 0, q); }

array<int, 2> a[N];
int t[N], ord[N];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	rep(i, 0, N << 1) s[i] = 0, mn[i] = inf;
	int n; cin >> n >> q;
	rep(i, 0, n) cin >> a[i][0] >> a[i][1];
	rep(i, 0, q) cin >> t[i], ord[i] = i;
	sort(a, a + n, [](const auto &x, const auto &y) { return min(x[0], x[1]) > min(y[0], y[1]); });
	sort(ord, ord + q, [&](int x, int y) { return t[x] > t[y]; });
	int64_t ans = 0;
	for (int i = 0, j = 0; i < n; ++i) {
		bool b = 0; if (a[i][0] < a[i][1]) swap(a[i][0], a[i][1]), b = 1;
		while (j < q && a[i][1] <= t[ord[j]]) upd(ord[j], t[ord[j]]), ++j;
		int p = find(a[i][0]);
		if (!p && b) swap(a[i][0], a[i][1]);
		ans += a[i][sum(p, q)];
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2944 KB Output is correct
2 Correct 4 ms 2944 KB Output is correct
3 Correct 4 ms 2944 KB Output is correct
4 Correct 3 ms 2944 KB Output is correct
5 Correct 3 ms 2944 KB Output is correct
6 Correct 3 ms 2944 KB Output is correct
7 Correct 3 ms 3072 KB Output is correct
8 Correct 4 ms 2944 KB Output is correct
9 Correct 3 ms 2944 KB Output is correct
10 Correct 3 ms 2944 KB Output is correct
11 Correct 3 ms 2944 KB Output is correct
12 Correct 3 ms 2944 KB Output is correct
13 Correct 3 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2944 KB Output is correct
2 Correct 4 ms 2944 KB Output is correct
3 Correct 4 ms 2944 KB Output is correct
4 Correct 3 ms 2944 KB Output is correct
5 Correct 3 ms 2944 KB Output is correct
6 Correct 3 ms 2944 KB Output is correct
7 Correct 3 ms 3072 KB Output is correct
8 Correct 4 ms 2944 KB Output is correct
9 Correct 3 ms 2944 KB Output is correct
10 Correct 3 ms 2944 KB Output is correct
11 Correct 3 ms 2944 KB Output is correct
12 Correct 3 ms 2944 KB Output is correct
13 Correct 3 ms 2944 KB Output is correct
14 Correct 12 ms 3328 KB Output is correct
15 Correct 23 ms 3968 KB Output is correct
16 Correct 29 ms 4224 KB Output is correct
17 Correct 43 ms 4736 KB Output is correct
18 Correct 41 ms 4736 KB Output is correct
19 Correct 44 ms 4736 KB Output is correct
20 Correct 62 ms 4728 KB Output is correct
21 Correct 39 ms 4728 KB Output is correct
22 Correct 35 ms 4224 KB Output is correct
23 Correct 31 ms 4224 KB Output is correct
24 Correct 34 ms 4224 KB Output is correct
25 Correct 29 ms 4224 KB Output is correct
26 Correct 38 ms 4480 KB Output is correct
27 Correct 38 ms 4732 KB Output is correct
28 Correct 38 ms 4736 KB Output is correct
29 Correct 39 ms 4736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2944 KB Output is correct
2 Correct 4 ms 2944 KB Output is correct
3 Correct 4 ms 2944 KB Output is correct
4 Correct 3 ms 2944 KB Output is correct
5 Correct 3 ms 2944 KB Output is correct
6 Correct 3 ms 2944 KB Output is correct
7 Correct 3 ms 3072 KB Output is correct
8 Correct 4 ms 2944 KB Output is correct
9 Correct 3 ms 2944 KB Output is correct
10 Correct 3 ms 2944 KB Output is correct
11 Correct 3 ms 2944 KB Output is correct
12 Correct 3 ms 2944 KB Output is correct
13 Correct 3 ms 2944 KB Output is correct
14 Correct 12 ms 3328 KB Output is correct
15 Correct 23 ms 3968 KB Output is correct
16 Correct 29 ms 4224 KB Output is correct
17 Correct 43 ms 4736 KB Output is correct
18 Correct 41 ms 4736 KB Output is correct
19 Correct 44 ms 4736 KB Output is correct
20 Correct 62 ms 4728 KB Output is correct
21 Correct 39 ms 4728 KB Output is correct
22 Correct 35 ms 4224 KB Output is correct
23 Correct 31 ms 4224 KB Output is correct
24 Correct 34 ms 4224 KB Output is correct
25 Correct 29 ms 4224 KB Output is correct
26 Correct 38 ms 4480 KB Output is correct
27 Correct 38 ms 4732 KB Output is correct
28 Correct 38 ms 4736 KB Output is correct
29 Correct 39 ms 4736 KB Output is correct
30 Correct 103 ms 6656 KB Output is correct
31 Correct 125 ms 7800 KB Output is correct
32 Correct 158 ms 9208 KB Output is correct
33 Correct 217 ms 12024 KB Output is correct
34 Correct 94 ms 6392 KB Output is correct
35 Correct 212 ms 11896 KB Output is correct
36 Correct 201 ms 11896 KB Output is correct
37 Correct 208 ms 11896 KB Output is correct
38 Correct 208 ms 11904 KB Output is correct
39 Correct 225 ms 11896 KB Output is correct
40 Correct 177 ms 11640 KB Output is correct
41 Correct 204 ms 11896 KB Output is correct
42 Correct 230 ms 11900 KB Output is correct
43 Correct 171 ms 11128 KB Output is correct
44 Correct 165 ms 11128 KB Output is correct
45 Correct 191 ms 11128 KB Output is correct
46 Correct 179 ms 9976 KB Output is correct
47 Correct 201 ms 9848 KB Output is correct
48 Correct 208 ms 11900 KB Output is correct
49 Correct 214 ms 11924 KB Output is correct