Submission #255677

# Submission time Handle Problem Language Result Execution time Memory
255677 2020-08-01T14:14:20 Z islingr Examination (JOI19_examination) C++17
100 / 100
561 ms 14172 KB
#include <bits/stdc++.h>
using namespace std;

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

const int N = 1 << 17;
int n, ans[N];
struct P { int x, y, z, i; bool first; } a[2 * N], b[2 * N], c[2 * N];

void cdq2(int l, int r) {
	if (r - l == 1) return;
	int m = (l + r) / 2;
	cdq2(l, m); cdq2(m, r);
	int i = l, j = m, k = l, cnt = 0;
	while (i < m && j < r) {
		if (b[j].z <= b[i].z) {
			if (!b[i].i && b[i].first) ++cnt;
			c[k++] = b[i++];
		} else {
			if (b[j].i && !b[j].first) ans[b[j].i] += cnt;
			c[k++] = b[j++];
		}
	}
	while (i < m) c[k++] = b[i++];
	while (j < r) {
		if (b[j].i && !b[j].first) ans[b[j].i] += cnt;
		c[k++] = b[j++];
	}
	rep(i, l, r) b[i] = c[i];
}

void cdq(int l, int r) {
	if (r - l == 1) return;
	int m = (l + r) / 2;
	cdq(l, m); cdq(m, r);
	rep(i, l, r) a[i].first = i < m;
	merge(a + l, a + m, a + m, a + r, b + l, [](P &a, P &b) { return pair(-a.y, a.i) < pair(-b.y, b.i); });
	rep(i, l, r) a[i] = b[i];
	cdq2(l, r);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	int q; cin >> n >> q;
	rep(i, 0, n) {
		int x, y; cin >> x >> y;
		a[i] = {x, y, x + y, 0};
	}
	rep(i, 0, q) {
		int x, y, z; cin >> x >> y >> z;
		a[i + n] = {x, y, z, i + 1};
	}
	sort(a, a + n + q, [](P &a, P &b) { return pair(-a.x, a.i) < pair(-b.x, b.i); });
	cdq(0, n + q);
	rep(i, 0, q) cout << ans[i + 1] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 11 ms 896 KB Output is correct
8 Correct 11 ms 896 KB Output is correct
9 Correct 11 ms 896 KB Output is correct
10 Correct 10 ms 896 KB Output is correct
11 Correct 9 ms 896 KB Output is correct
12 Correct 7 ms 768 KB Output is correct
13 Correct 9 ms 896 KB Output is correct
14 Correct 9 ms 896 KB Output is correct
15 Correct 9 ms 896 KB Output is correct
16 Correct 6 ms 768 KB Output is correct
17 Correct 11 ms 896 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 390 ms 14072 KB Output is correct
2 Correct 383 ms 13944 KB Output is correct
3 Correct 386 ms 13944 KB Output is correct
4 Correct 326 ms 13948 KB Output is correct
5 Correct 290 ms 14072 KB Output is correct
6 Correct 235 ms 13944 KB Output is correct
7 Correct 346 ms 14072 KB Output is correct
8 Correct 352 ms 13944 KB Output is correct
9 Correct 335 ms 14072 KB Output is correct
10 Correct 259 ms 13944 KB Output is correct
11 Correct 278 ms 13816 KB Output is correct
12 Correct 206 ms 13688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 390 ms 14072 KB Output is correct
2 Correct 383 ms 13944 KB Output is correct
3 Correct 386 ms 13944 KB Output is correct
4 Correct 326 ms 13948 KB Output is correct
5 Correct 290 ms 14072 KB Output is correct
6 Correct 235 ms 13944 KB Output is correct
7 Correct 346 ms 14072 KB Output is correct
8 Correct 352 ms 13944 KB Output is correct
9 Correct 335 ms 14072 KB Output is correct
10 Correct 259 ms 13944 KB Output is correct
11 Correct 278 ms 13816 KB Output is correct
12 Correct 206 ms 13688 KB Output is correct
13 Correct 549 ms 14072 KB Output is correct
14 Correct 519 ms 13992 KB Output is correct
15 Correct 388 ms 14032 KB Output is correct
16 Correct 457 ms 13968 KB Output is correct
17 Correct 406 ms 14000 KB Output is correct
18 Correct 307 ms 14000 KB Output is correct
19 Correct 553 ms 14068 KB Output is correct
20 Correct 560 ms 14172 KB Output is correct
21 Correct 507 ms 14072 KB Output is correct
22 Correct 261 ms 13816 KB Output is correct
23 Correct 276 ms 13816 KB Output is correct
24 Correct 208 ms 13688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 11 ms 896 KB Output is correct
8 Correct 11 ms 896 KB Output is correct
9 Correct 11 ms 896 KB Output is correct
10 Correct 10 ms 896 KB Output is correct
11 Correct 9 ms 896 KB Output is correct
12 Correct 7 ms 768 KB Output is correct
13 Correct 9 ms 896 KB Output is correct
14 Correct 9 ms 896 KB Output is correct
15 Correct 9 ms 896 KB Output is correct
16 Correct 6 ms 768 KB Output is correct
17 Correct 11 ms 896 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 390 ms 14072 KB Output is correct
20 Correct 383 ms 13944 KB Output is correct
21 Correct 386 ms 13944 KB Output is correct
22 Correct 326 ms 13948 KB Output is correct
23 Correct 290 ms 14072 KB Output is correct
24 Correct 235 ms 13944 KB Output is correct
25 Correct 346 ms 14072 KB Output is correct
26 Correct 352 ms 13944 KB Output is correct
27 Correct 335 ms 14072 KB Output is correct
28 Correct 259 ms 13944 KB Output is correct
29 Correct 278 ms 13816 KB Output is correct
30 Correct 206 ms 13688 KB Output is correct
31 Correct 549 ms 14072 KB Output is correct
32 Correct 519 ms 13992 KB Output is correct
33 Correct 388 ms 14032 KB Output is correct
34 Correct 457 ms 13968 KB Output is correct
35 Correct 406 ms 14000 KB Output is correct
36 Correct 307 ms 14000 KB Output is correct
37 Correct 553 ms 14068 KB Output is correct
38 Correct 560 ms 14172 KB Output is correct
39 Correct 507 ms 14072 KB Output is correct
40 Correct 261 ms 13816 KB Output is correct
41 Correct 276 ms 13816 KB Output is correct
42 Correct 208 ms 13688 KB Output is correct
43 Correct 561 ms 13880 KB Output is correct
44 Correct 556 ms 13944 KB Output is correct
45 Correct 543 ms 13944 KB Output is correct
46 Correct 453 ms 13940 KB Output is correct
47 Correct 409 ms 13944 KB Output is correct
48 Correct 318 ms 13816 KB Output is correct
49 Correct 490 ms 13924 KB Output is correct
50 Correct 495 ms 14028 KB Output is correct
51 Correct 469 ms 14072 KB Output is correct
52 Correct 432 ms 13816 KB Output is correct
53 Correct 296 ms 13816 KB Output is correct