답안 #255657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255657 2020-08-01T13:37:33 Z islingr Examination (JOI19_examination) C++17
100 / 100
828 ms 9848 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, 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] = {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';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 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 1 ms 384 KB Output is correct
7 Correct 14 ms 768 KB Output is correct
8 Correct 14 ms 768 KB Output is correct
9 Correct 14 ms 768 KB Output is correct
10 Correct 18 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 11 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 768 KB Output is correct
18 Correct 7 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 543 ms 9632 KB Output is correct
2 Correct 547 ms 9840 KB Output is correct
3 Correct 533 ms 9720 KB Output is correct
4 Correct 488 ms 9720 KB Output is correct
5 Correct 415 ms 9720 KB Output is correct
6 Correct 309 ms 9720 KB Output is correct
7 Correct 470 ms 9720 KB Output is correct
8 Correct 490 ms 9848 KB Output is correct
9 Correct 472 ms 9720 KB Output is correct
10 Correct 413 ms 9452 KB Output is correct
11 Correct 388 ms 9568 KB Output is correct
12 Correct 287 ms 9336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 543 ms 9632 KB Output is correct
2 Correct 547 ms 9840 KB Output is correct
3 Correct 533 ms 9720 KB Output is correct
4 Correct 488 ms 9720 KB Output is correct
5 Correct 415 ms 9720 KB Output is correct
6 Correct 309 ms 9720 KB Output is correct
7 Correct 470 ms 9720 KB Output is correct
8 Correct 490 ms 9848 KB Output is correct
9 Correct 472 ms 9720 KB Output is correct
10 Correct 413 ms 9452 KB Output is correct
11 Correct 388 ms 9568 KB Output is correct
12 Correct 287 ms 9336 KB Output is correct
13 Correct 733 ms 9680 KB Output is correct
14 Correct 717 ms 9848 KB Output is correct
15 Correct 532 ms 9720 KB Output is correct
16 Correct 648 ms 9720 KB Output is correct
17 Correct 577 ms 9720 KB Output is correct
18 Correct 411 ms 9720 KB Output is correct
19 Correct 725 ms 9720 KB Output is correct
20 Correct 723 ms 9756 KB Output is correct
21 Correct 662 ms 9700 KB Output is correct
22 Correct 429 ms 9528 KB Output is correct
23 Correct 401 ms 9592 KB Output is correct
24 Correct 299 ms 9444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 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 1 ms 384 KB Output is correct
7 Correct 14 ms 768 KB Output is correct
8 Correct 14 ms 768 KB Output is correct
9 Correct 14 ms 768 KB Output is correct
10 Correct 18 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 11 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 768 KB Output is correct
18 Correct 7 ms 640 KB Output is correct
19 Correct 543 ms 9632 KB Output is correct
20 Correct 547 ms 9840 KB Output is correct
21 Correct 533 ms 9720 KB Output is correct
22 Correct 488 ms 9720 KB Output is correct
23 Correct 415 ms 9720 KB Output is correct
24 Correct 309 ms 9720 KB Output is correct
25 Correct 470 ms 9720 KB Output is correct
26 Correct 490 ms 9848 KB Output is correct
27 Correct 472 ms 9720 KB Output is correct
28 Correct 413 ms 9452 KB Output is correct
29 Correct 388 ms 9568 KB Output is correct
30 Correct 287 ms 9336 KB Output is correct
31 Correct 733 ms 9680 KB Output is correct
32 Correct 717 ms 9848 KB Output is correct
33 Correct 532 ms 9720 KB Output is correct
34 Correct 648 ms 9720 KB Output is correct
35 Correct 577 ms 9720 KB Output is correct
36 Correct 411 ms 9720 KB Output is correct
37 Correct 725 ms 9720 KB Output is correct
38 Correct 723 ms 9756 KB Output is correct
39 Correct 662 ms 9700 KB Output is correct
40 Correct 429 ms 9528 KB Output is correct
41 Correct 401 ms 9592 KB Output is correct
42 Correct 299 ms 9444 KB Output is correct
43 Correct 747 ms 9592 KB Output is correct
44 Correct 828 ms 9696 KB Output is correct
45 Correct 714 ms 9720 KB Output is correct
46 Correct 667 ms 9724 KB Output is correct
47 Correct 578 ms 9592 KB Output is correct
48 Correct 440 ms 9420 KB Output is correct
49 Correct 648 ms 9720 KB Output is correct
50 Correct 654 ms 9720 KB Output is correct
51 Correct 635 ms 9724 KB Output is correct
52 Correct 552 ms 9464 KB Output is correct
53 Correct 387 ms 9592 KB Output is correct