Submission #255661

# Submission time Handle Problem Language Result Execution time Memory
255661 2020-08-01T13:41:52 Z islingr Examination (JOI19_examination) C++17
100 / 100
739 ms 9528 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], tmp[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 (a[j].z <= a[i].z) {
			if (!a[i].i && a[i].first) ++cnt;
			tmp[k++] = a[i++];
		} else {
			if (a[j].i && !a[j].first) ans[a[j].i] += cnt;
			tmp[k++] = a[j++];
		}
	}
	while (i < m) tmp[k++] = a[i++];
	while (j < r) {
		if (a[j].i && !a[j].first) ans[a[j].i] += cnt;
		tmp[k++] = a[j++];
	}
	rep(i, l, r) a[i] = tmp[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;
	sort(a + l, a + r, [](P &a, P &b) { return pair(-a.y, a.i) < pair(-b.y, 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 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 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 14 ms 768 KB Output is correct
8 Correct 15 ms 768 KB Output is correct
9 Correct 15 ms 780 KB Output is correct
10 Correct 14 ms 768 KB Output is correct
11 Correct 12 ms 768 KB Output is correct
12 Correct 10 ms 624 KB Output is correct
13 Correct 11 ms 800 KB Output is correct
14 Correct 11 ms 768 KB Output is correct
15 Correct 12 ms 768 KB Output is correct
16 Correct 8 ms 640 KB Output is correct
17 Correct 15 ms 768 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 617 ms 9528 KB Output is correct
2 Correct 542 ms 9336 KB Output is correct
3 Correct 539 ms 9368 KB Output is correct
4 Correct 509 ms 9372 KB Output is correct
5 Correct 443 ms 9508 KB Output is correct
6 Correct 326 ms 9464 KB Output is correct
7 Correct 483 ms 9332 KB Output is correct
8 Correct 547 ms 9464 KB Output is correct
9 Correct 502 ms 9464 KB Output is correct
10 Correct 412 ms 9208 KB Output is correct
11 Correct 391 ms 9304 KB Output is correct
12 Correct 290 ms 8952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 617 ms 9528 KB Output is correct
2 Correct 542 ms 9336 KB Output is correct
3 Correct 539 ms 9368 KB Output is correct
4 Correct 509 ms 9372 KB Output is correct
5 Correct 443 ms 9508 KB Output is correct
6 Correct 326 ms 9464 KB Output is correct
7 Correct 483 ms 9332 KB Output is correct
8 Correct 547 ms 9464 KB Output is correct
9 Correct 502 ms 9464 KB Output is correct
10 Correct 412 ms 9208 KB Output is correct
11 Correct 391 ms 9304 KB Output is correct
12 Correct 290 ms 8952 KB Output is correct
13 Correct 731 ms 9356 KB Output is correct
14 Correct 714 ms 9336 KB Output is correct
15 Correct 539 ms 9464 KB Output is correct
16 Correct 688 ms 9336 KB Output is correct
17 Correct 584 ms 9336 KB Output is correct
18 Correct 417 ms 9336 KB Output is correct
19 Correct 729 ms 9464 KB Output is correct
20 Correct 736 ms 9336 KB Output is correct
21 Correct 675 ms 9336 KB Output is correct
22 Correct 416 ms 9208 KB Output is correct
23 Correct 390 ms 9208 KB Output is correct
24 Correct 298 ms 8952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 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 14 ms 768 KB Output is correct
8 Correct 15 ms 768 KB Output is correct
9 Correct 15 ms 780 KB Output is correct
10 Correct 14 ms 768 KB Output is correct
11 Correct 12 ms 768 KB Output is correct
12 Correct 10 ms 624 KB Output is correct
13 Correct 11 ms 800 KB Output is correct
14 Correct 11 ms 768 KB Output is correct
15 Correct 12 ms 768 KB Output is correct
16 Correct 8 ms 640 KB Output is correct
17 Correct 15 ms 768 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
19 Correct 617 ms 9528 KB Output is correct
20 Correct 542 ms 9336 KB Output is correct
21 Correct 539 ms 9368 KB Output is correct
22 Correct 509 ms 9372 KB Output is correct
23 Correct 443 ms 9508 KB Output is correct
24 Correct 326 ms 9464 KB Output is correct
25 Correct 483 ms 9332 KB Output is correct
26 Correct 547 ms 9464 KB Output is correct
27 Correct 502 ms 9464 KB Output is correct
28 Correct 412 ms 9208 KB Output is correct
29 Correct 391 ms 9304 KB Output is correct
30 Correct 290 ms 8952 KB Output is correct
31 Correct 731 ms 9356 KB Output is correct
32 Correct 714 ms 9336 KB Output is correct
33 Correct 539 ms 9464 KB Output is correct
34 Correct 688 ms 9336 KB Output is correct
35 Correct 584 ms 9336 KB Output is correct
36 Correct 417 ms 9336 KB Output is correct
37 Correct 729 ms 9464 KB Output is correct
38 Correct 736 ms 9336 KB Output is correct
39 Correct 675 ms 9336 KB Output is correct
40 Correct 416 ms 9208 KB Output is correct
41 Correct 390 ms 9208 KB Output is correct
42 Correct 298 ms 8952 KB Output is correct
43 Correct 734 ms 9376 KB Output is correct
44 Correct 739 ms 9336 KB Output is correct
45 Correct 730 ms 9464 KB Output is correct
46 Correct 667 ms 9464 KB Output is correct
47 Correct 640 ms 9464 KB Output is correct
48 Correct 428 ms 9084 KB Output is correct
49 Correct 651 ms 9464 KB Output is correct
50 Correct 667 ms 9492 KB Output is correct
51 Correct 647 ms 9336 KB Output is correct
52 Correct 546 ms 9208 KB Output is correct
53 Correct 390 ms 9208 KB Output is correct