답안 #492695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492695 2021-12-08T12:34:58 Z zhougz Examination (JOI19_examination) C++17
100 / 100
157 ms 10800 KB
/**
 *    author: zhougz
 *    created: 08/12/2021 19:18:23
**/
#include <bits/stdc++.h>

using namespace std;

int n, q;
const int MAXN = 100'050, MAXQ = 100'050;

struct ele {
	int x, y, z, idx;
};

vector<ele> arr;

int idx[MAXN + MAXQ], fw[MAXN + MAXQ], res[MAXQ];

int lsb(int x) {
	return x & -x;
}

void update(int x) {
	for (x++; x <= n + q; x += lsb(x)) {
		fw[x]++;
	}
}

int query(int x) {
	int ret = 0;
	for (x++; x != 0; x -= lsb(x)) {
		ret += fw[x];
	}
	return ret;
}

int query(int l, int r) {
	return query(r) - query(l - 1);
}

// The double sweep-line method.
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> q;
	arr.resize(n + q);
	for (int i = 0; i < n; i++) {
		cin >> arr[i].x >> arr[i].y;
		arr[i].z = arr[i].x + arr[i].y;
		arr[i].idx = i;
	}
	for (int i = n; i < n + q; i++) {
		cin >> arr[i].x >> arr[i].y >> arr[i].z;
		arr[i].z = max(arr[i].z, arr[i].x + arr[i].y);
		arr[i].idx = i;
	}
	auto by_z = [](const ele &l, const ele &r) {
		return l.z < r.z;
	};
	sort(arr.begin(), arr.end(), by_z);
	for (int i = 0; i < n + q; i++) {
		idx[arr[i].idx] = lower_bound(arr.begin(), arr.end(), arr[i], by_z) - arr.begin();
	}
	sort(arr.begin(), arr.end(), [](const ele &l, const ele &r) {
		if (l.y != r.y) {
			return l.y > r.y;
		}
		if (l.z != r.z) {
			return l.z > r.z;
		}
		return l.idx < r.idx; // Students first for this sweep
	});
	for (const auto &[x, y, z, id] : arr) {
		if (id < n) { // Student
			update(idx[id]);
		} else { // Query
			res[id - n] += query(idx[id], n + q - 1);
		}
	}
	fill(fw, fw + MAXN + MAXQ, 0);
	sort(arr.begin(), arr.end(), [](const ele &l, const ele &r) {
		if (l.x != r.x) {
			return l.x < r.x;
		}
		if (l.z != r.z) {
			return l.z < r.z;
		}
		return l.idx > r.idx; // Prevent removing too much (same x-coordinate)
	});
	for (const auto &[x, y, z, id] : arr) {
		if (id < n) {
			update(idx[id]);
		} else {
			res[id - n] -= query(idx[id], n + q - 1);
		}
	}
	for (int i = 0; i < q; i++) {
		cout << res[i] << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1104 KB Output is correct
2 Correct 1 ms 1104 KB Output is correct
3 Correct 1 ms 1104 KB Output is correct
4 Correct 2 ms 1104 KB Output is correct
5 Correct 1 ms 1104 KB Output is correct
6 Correct 1 ms 1104 KB Output is correct
7 Correct 4 ms 1360 KB Output is correct
8 Correct 5 ms 1320 KB Output is correct
9 Correct 4 ms 1352 KB Output is correct
10 Correct 3 ms 1236 KB Output is correct
11 Correct 4 ms 1232 KB Output is correct
12 Correct 3 ms 1232 KB Output is correct
13 Correct 4 ms 1372 KB Output is correct
14 Correct 4 ms 1292 KB Output is correct
15 Correct 5 ms 1360 KB Output is correct
16 Correct 3 ms 1260 KB Output is correct
17 Correct 4 ms 1232 KB Output is correct
18 Correct 3 ms 1220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 8384 KB Output is correct
2 Correct 128 ms 8396 KB Output is correct
3 Correct 138 ms 8408 KB Output is correct
4 Correct 122 ms 7660 KB Output is correct
5 Correct 113 ms 7660 KB Output is correct
6 Correct 94 ms 6980 KB Output is correct
7 Correct 122 ms 8312 KB Output is correct
8 Correct 129 ms 8280 KB Output is correct
9 Correct 120 ms 8192 KB Output is correct
10 Correct 97 ms 7412 KB Output is correct
11 Correct 94 ms 7420 KB Output is correct
12 Correct 73 ms 6516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 8384 KB Output is correct
2 Correct 128 ms 8396 KB Output is correct
3 Correct 138 ms 8408 KB Output is correct
4 Correct 122 ms 7660 KB Output is correct
5 Correct 113 ms 7660 KB Output is correct
6 Correct 94 ms 6980 KB Output is correct
7 Correct 122 ms 8312 KB Output is correct
8 Correct 129 ms 8280 KB Output is correct
9 Correct 120 ms 8192 KB Output is correct
10 Correct 97 ms 7412 KB Output is correct
11 Correct 94 ms 7420 KB Output is correct
12 Correct 73 ms 6516 KB Output is correct
13 Correct 125 ms 8832 KB Output is correct
14 Correct 119 ms 8764 KB Output is correct
15 Correct 116 ms 8396 KB Output is correct
16 Correct 115 ms 8052 KB Output is correct
17 Correct 115 ms 8060 KB Output is correct
18 Correct 89 ms 6924 KB Output is correct
19 Correct 122 ms 8820 KB Output is correct
20 Correct 123 ms 8808 KB Output is correct
21 Correct 134 ms 8824 KB Output is correct
22 Correct 103 ms 7496 KB Output is correct
23 Correct 103 ms 7500 KB Output is correct
24 Correct 89 ms 6596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1104 KB Output is correct
2 Correct 1 ms 1104 KB Output is correct
3 Correct 1 ms 1104 KB Output is correct
4 Correct 2 ms 1104 KB Output is correct
5 Correct 1 ms 1104 KB Output is correct
6 Correct 1 ms 1104 KB Output is correct
7 Correct 4 ms 1360 KB Output is correct
8 Correct 5 ms 1320 KB Output is correct
9 Correct 4 ms 1352 KB Output is correct
10 Correct 3 ms 1236 KB Output is correct
11 Correct 4 ms 1232 KB Output is correct
12 Correct 3 ms 1232 KB Output is correct
13 Correct 4 ms 1372 KB Output is correct
14 Correct 4 ms 1292 KB Output is correct
15 Correct 5 ms 1360 KB Output is correct
16 Correct 3 ms 1260 KB Output is correct
17 Correct 4 ms 1232 KB Output is correct
18 Correct 3 ms 1220 KB Output is correct
19 Correct 124 ms 8384 KB Output is correct
20 Correct 128 ms 8396 KB Output is correct
21 Correct 138 ms 8408 KB Output is correct
22 Correct 122 ms 7660 KB Output is correct
23 Correct 113 ms 7660 KB Output is correct
24 Correct 94 ms 6980 KB Output is correct
25 Correct 122 ms 8312 KB Output is correct
26 Correct 129 ms 8280 KB Output is correct
27 Correct 120 ms 8192 KB Output is correct
28 Correct 97 ms 7412 KB Output is correct
29 Correct 94 ms 7420 KB Output is correct
30 Correct 73 ms 6516 KB Output is correct
31 Correct 125 ms 8832 KB Output is correct
32 Correct 119 ms 8764 KB Output is correct
33 Correct 116 ms 8396 KB Output is correct
34 Correct 115 ms 8052 KB Output is correct
35 Correct 115 ms 8060 KB Output is correct
36 Correct 89 ms 6924 KB Output is correct
37 Correct 122 ms 8820 KB Output is correct
38 Correct 123 ms 8808 KB Output is correct
39 Correct 134 ms 8824 KB Output is correct
40 Correct 103 ms 7496 KB Output is correct
41 Correct 103 ms 7500 KB Output is correct
42 Correct 89 ms 6596 KB Output is correct
43 Correct 144 ms 10784 KB Output is correct
44 Correct 144 ms 10800 KB Output is correct
45 Correct 141 ms 10736 KB Output is correct
46 Correct 129 ms 9156 KB Output is correct
47 Correct 126 ms 9208 KB Output is correct
48 Correct 96 ms 6724 KB Output is correct
49 Correct 141 ms 10736 KB Output is correct
50 Correct 157 ms 10732 KB Output is correct
51 Correct 131 ms 10616 KB Output is correct
52 Correct 118 ms 9068 KB Output is correct
53 Correct 114 ms 8308 KB Output is correct