Submission #372903

# Submission time Handle Problem Language Result Execution time Memory
372903 2021-03-02T08:29:19 Z Ahoora Fortune Telling 2 (JOI14_fortune_telling2) C++14
35 / 100
2324 ms 262148 KB
#include<bits/stdc++.h>
using namespace std;

const int N = 3 * 2 * 1000 * 100 + 10, LG = 20;
int n, k, a[N], b[N], t[N], kol[N];
unordered_map<int, int> fen[N];

void UPD(int id, int x) {
	kol[id]++;
	for (++x; x < N; x += x & -x)
		fen[id][x]++;
}

void upd(int x, int y) {
	for (++x; x < N; x += x & -x)
		UPD(x, y);
}

int GET(int id, int x) {
	int res = 0;
	for (; x; x -= x & -x)
		res += fen[id][x];
	return res;
}

int get(int x, int y) {
	int res = 0;
	for (; x; x -= x & -x)
		res += kol[x] - GET(x, y);
	return res;
}

inline int inp() {
	int res = 0;
	char c = '0';
	while (c >= '0' && c <= '9') {
		((res *= 10) += c - '0');
		c = getchar();
	}
	return res;
}

int main() { 
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	n = inp(), k = inp();
	vector<int> all;
	for (int i = 0; i < n; i++) {
		a[i] = inp(), b[i] = inp();
		for (auto x: {a[i], b[i]})
			all.push_back(x);
	}
	for (int i = 0; i < k; i++)
		t[i] = inp(), all.push_back(t[i]);
	sort(all.begin(), all.end());
	all.resize(unique(all.begin(), all.end()) - all.begin());
	for (int i = 0; i < n; i++)
		for (auto x: {&a[i], &b[i]})
			*x = lower_bound(all.begin(), all.end(), *x) - all.begin();
	for (int i = 0; i < k; i++)
		t[i] = lower_bound(all.begin(), all.end(), t[i]) - all.begin();
	reverse(t, t + k);
	for (int i = 0; i < k; i++)
		upd(i, t[i]);
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		int fl = 0;
		if (a[i] > b[i])
			fl++, swap(a[i], b[i]);
		int ind = 0;
		for (int j = LG - 1; j >= 0; j--) {
			if (ind + (1 << j) > k)
				continue;
			int id = ind + (1 << j);
			int x = GET(id, b[i]) - GET(id, a[i]); 
			if (x == 0) 
				ind += 1 << j;
		}
		int res = get(ind, b[i]);
		if (ind == k) {
			fl += res;
			ans += (fl & 1? all[b[i]]: all[a[i]]);
		}
		else {
			fl = 0;
			fl += res;
			swap(a[i], b[i]);
			ans += (fl & 1? all[b[i]]: all[a[i]]);
		}
	}
	printf("%lld\n", ans);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 35052 KB Output is correct
2 Correct 38 ms 35692 KB Output is correct
3 Correct 40 ms 36332 KB Output is correct
4 Correct 41 ms 36460 KB Output is correct
5 Correct 40 ms 36460 KB Output is correct
6 Correct 45 ms 36332 KB Output is correct
7 Correct 41 ms 36716 KB Output is correct
8 Correct 39 ms 36076 KB Output is correct
9 Correct 38 ms 35840 KB Output is correct
10 Correct 35 ms 35436 KB Output is correct
11 Correct 37 ms 35584 KB Output is correct
12 Correct 37 ms 35564 KB Output is correct
13 Correct 39 ms 35820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 35052 KB Output is correct
2 Correct 38 ms 35692 KB Output is correct
3 Correct 40 ms 36332 KB Output is correct
4 Correct 41 ms 36460 KB Output is correct
5 Correct 40 ms 36460 KB Output is correct
6 Correct 45 ms 36332 KB Output is correct
7 Correct 41 ms 36716 KB Output is correct
8 Correct 39 ms 36076 KB Output is correct
9 Correct 38 ms 35840 KB Output is correct
10 Correct 35 ms 35436 KB Output is correct
11 Correct 37 ms 35584 KB Output is correct
12 Correct 37 ms 35564 KB Output is correct
13 Correct 39 ms 35820 KB Output is correct
14 Correct 369 ms 70128 KB Output is correct
15 Correct 947 ms 110044 KB Output is correct
16 Correct 1552 ms 152460 KB Output is correct
17 Correct 2202 ms 193756 KB Output is correct
18 Correct 2258 ms 194332 KB Output is correct
19 Correct 2152 ms 186432 KB Output is correct
20 Correct 2324 ms 202724 KB Output is correct
21 Correct 1941 ms 175620 KB Output is correct
22 Correct 1192 ms 170456 KB Output is correct
23 Correct 1035 ms 150268 KB Output is correct
24 Correct 1004 ms 142960 KB Output is correct
25 Correct 1173 ms 171324 KB Output is correct
26 Correct 1369 ms 140384 KB Output is correct
27 Correct 1788 ms 150692 KB Output is correct
28 Correct 1355 ms 145636 KB Output is correct
29 Correct 1442 ms 162628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 35052 KB Output is correct
2 Correct 38 ms 35692 KB Output is correct
3 Correct 40 ms 36332 KB Output is correct
4 Correct 41 ms 36460 KB Output is correct
5 Correct 40 ms 36460 KB Output is correct
6 Correct 45 ms 36332 KB Output is correct
7 Correct 41 ms 36716 KB Output is correct
8 Correct 39 ms 36076 KB Output is correct
9 Correct 38 ms 35840 KB Output is correct
10 Correct 35 ms 35436 KB Output is correct
11 Correct 37 ms 35584 KB Output is correct
12 Correct 37 ms 35564 KB Output is correct
13 Correct 39 ms 35820 KB Output is correct
14 Correct 369 ms 70128 KB Output is correct
15 Correct 947 ms 110044 KB Output is correct
16 Correct 1552 ms 152460 KB Output is correct
17 Correct 2202 ms 193756 KB Output is correct
18 Correct 2258 ms 194332 KB Output is correct
19 Correct 2152 ms 186432 KB Output is correct
20 Correct 2324 ms 202724 KB Output is correct
21 Correct 1941 ms 175620 KB Output is correct
22 Correct 1192 ms 170456 KB Output is correct
23 Correct 1035 ms 150268 KB Output is correct
24 Correct 1004 ms 142960 KB Output is correct
25 Correct 1173 ms 171324 KB Output is correct
26 Correct 1369 ms 140384 KB Output is correct
27 Correct 1788 ms 150692 KB Output is correct
28 Correct 1355 ms 145636 KB Output is correct
29 Correct 1442 ms 162628 KB Output is correct
30 Runtime error 1451 ms 262148 KB Execution killed with signal 9
31 Halted 0 ms 0 KB -