Submission #255649

# Submission time Handle Problem Language Result Execution time Memory
255649 2020-08-01T13:29:36 Z islingr Examination (JOI19_examination) C++17
100 / 100
746 ms 14200 KB
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)

const int N = 1 << 17;

int n;
struct P { int x, y, z, i; bool first; } a[2 * N], tmp[2 * N];
int ans[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, m) a[i].first = 1;
	rep(i, m, r) a[i].first = 0;
	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 + q] = {x, y, x + y, 0};
	}
	rep(i, 0, q) {
		int x, y, z; cin >> x >> y >> z;
		a[i] = {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 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 15 ms 768 KB Output is correct
8 Correct 16 ms 768 KB Output is correct
9 Correct 14 ms 768 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 640 KB Output is correct
13 Correct 16 ms 768 KB Output is correct
14 Correct 11 ms 768 KB Output is correct
15 Correct 11 ms 768 KB Output is correct
16 Correct 8 ms 640 KB Output is correct
17 Correct 11 ms 760 KB Output is correct
18 Correct 7 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 568 ms 11768 KB Output is correct
2 Correct 545 ms 11668 KB Output is correct
3 Correct 546 ms 11648 KB Output is correct
4 Correct 491 ms 10920 KB Output is correct
5 Correct 421 ms 10904 KB Output is correct
6 Correct 323 ms 10232 KB Output is correct
7 Correct 481 ms 11640 KB Output is correct
8 Correct 500 ms 11768 KB Output is correct
9 Correct 482 ms 11444 KB Output is correct
10 Correct 415 ms 10872 KB Output is correct
11 Correct 380 ms 10748 KB Output is correct
12 Correct 294 ms 9852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 568 ms 11768 KB Output is correct
2 Correct 545 ms 11668 KB Output is correct
3 Correct 546 ms 11648 KB Output is correct
4 Correct 491 ms 10920 KB Output is correct
5 Correct 421 ms 10904 KB Output is correct
6 Correct 323 ms 10232 KB Output is correct
7 Correct 481 ms 11640 KB Output is correct
8 Correct 500 ms 11768 KB Output is correct
9 Correct 482 ms 11444 KB Output is correct
10 Correct 415 ms 10872 KB Output is correct
11 Correct 380 ms 10748 KB Output is correct
12 Correct 294 ms 9852 KB Output is correct
13 Correct 714 ms 12152 KB Output is correct
14 Correct 707 ms 12180 KB Output is correct
15 Correct 542 ms 11640 KB Output is correct
16 Correct 659 ms 11256 KB Output is correct
17 Correct 580 ms 11256 KB Output is correct
18 Correct 408 ms 10232 KB Output is correct
19 Correct 724 ms 12152 KB Output is correct
20 Correct 726 ms 12280 KB Output is correct
21 Correct 676 ms 12152 KB Output is correct
22 Correct 418 ms 10744 KB Output is correct
23 Correct 391 ms 10744 KB Output is correct
24 Correct 304 ms 9720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 15 ms 768 KB Output is correct
8 Correct 16 ms 768 KB Output is correct
9 Correct 14 ms 768 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 640 KB Output is correct
13 Correct 16 ms 768 KB Output is correct
14 Correct 11 ms 768 KB Output is correct
15 Correct 11 ms 768 KB Output is correct
16 Correct 8 ms 640 KB Output is correct
17 Correct 11 ms 760 KB Output is correct
18 Correct 7 ms 640 KB Output is correct
19 Correct 568 ms 11768 KB Output is correct
20 Correct 545 ms 11668 KB Output is correct
21 Correct 546 ms 11648 KB Output is correct
22 Correct 491 ms 10920 KB Output is correct
23 Correct 421 ms 10904 KB Output is correct
24 Correct 323 ms 10232 KB Output is correct
25 Correct 481 ms 11640 KB Output is correct
26 Correct 500 ms 11768 KB Output is correct
27 Correct 482 ms 11444 KB Output is correct
28 Correct 415 ms 10872 KB Output is correct
29 Correct 380 ms 10748 KB Output is correct
30 Correct 294 ms 9852 KB Output is correct
31 Correct 714 ms 12152 KB Output is correct
32 Correct 707 ms 12180 KB Output is correct
33 Correct 542 ms 11640 KB Output is correct
34 Correct 659 ms 11256 KB Output is correct
35 Correct 580 ms 11256 KB Output is correct
36 Correct 408 ms 10232 KB Output is correct
37 Correct 724 ms 12152 KB Output is correct
38 Correct 726 ms 12280 KB Output is correct
39 Correct 676 ms 12152 KB Output is correct
40 Correct 418 ms 10744 KB Output is correct
41 Correct 391 ms 10744 KB Output is correct
42 Correct 304 ms 9720 KB Output is correct
43 Correct 736 ms 14040 KB Output is correct
44 Correct 736 ms 13996 KB Output is correct
45 Correct 746 ms 13988 KB Output is correct
46 Correct 668 ms 12536 KB Output is correct
47 Correct 590 ms 12464 KB Output is correct
48 Correct 475 ms 10004 KB Output is correct
49 Correct 664 ms 13944 KB Output is correct
50 Correct 671 ms 14200 KB Output is correct
51 Correct 633 ms 13944 KB Output is correct
52 Correct 558 ms 12408 KB Output is correct
53 Correct 401 ms 11516 KB Output is correct