답안 #255533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255533 2020-08-01T07:52:24 Z islingr Examination (JOI19_examination) C++14
100 / 100
429 ms 10608 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 eb(x...) emplace_back(x)
#define lb(x...) lower_bound(x)
#define all(x) begin(x), end(x)

const int N = 1 << 17;
 
int n, m;
int t[4 * N];
int query(int l, int r) {
	int sum = 0;
	for (l += m, r += m; l < r; l >>= 1, r >>= 1) {
		if (l & 1) sum += t[l++];
		if (r & 1) sum += t[--r];
	}
	return sum;
}
void update(int p, int x) {
	for (t[p += m] += x; p >>= 1; ) t[p] = t[p << 1] + t[p << 1|1];
}

struct P {
	int x, y, z, i;
	bool operator<(const P &p) {
		return tuple<int, int, int>(-x, -y, i) < tuple<int, int, int>(-p.x, -p.y, p.i);
	}
} a[2 * N], tmp[2 * N];
int ans[N];

void cdq(int l, int r) {
	if (r - l == 1) return;
	int m = (l + r) / 2;
	cdq(l, m); cdq(m, r);
	vector<int> op;
	int i = l, j = m, k = l, cnt = 0;
	while (i < m && j < r)
		if (a[j].y <= a[i].y) {
			if (!a[i].i) ++cnt, update(a[i].z, 1), op.eb(a[i].z);
			tmp[k++] = a[i++];
		} else {
			if (a[j].i) ans[a[j].i] += cnt - query(0, a[j].z);
			tmp[k++] = a[j++];
		}
	while (i < m) tmp[k++] = a[i++];
	while (j < r) {
		if (a[j].i) ans[a[j].i] += cnt - query(0, a[j].z);
		tmp[k++] = a[j++];
	}
	rep(i, l, r) a[i] = tmp[i];
	for (int p : op) update(p, -1);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	vector<int> cmp;
	int q; cin >> n >> q;
	rep(i, 0, n) {
		int x, y; cin >> x >> y;
		a[i] = {x, y, x + y, 0};
		cmp.eb(x + y);
	}
	rep(i, 0, q) {
		int x, y, z; cin >> x >> y >> z;
		a[i + n] = {x, y, z, i + 1};
		cmp.eb(z);
	}
	sort(all(cmp)); cmp.resize(m = unique(all(cmp)) - begin(cmp));
	rep(i, 0, n + q) a[i].z = lb(all(cmp), a[i].z) - begin(cmp);
	sort(a, a + n + q); cdq(0, n + q);
	rep(i, 0, q) cout << ans[i + 1] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 8 ms 640 KB Output is correct
9 Correct 8 ms 640 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 6 ms 720 KB Output is correct
15 Correct 6 ms 640 KB Output is correct
16 Correct 7 ms 640 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 9452 KB Output is correct
2 Correct 244 ms 9456 KB Output is correct
3 Correct 238 ms 9452 KB Output is correct
4 Correct 204 ms 9332 KB Output is correct
5 Correct 213 ms 9456 KB Output is correct
6 Correct 142 ms 8816 KB Output is correct
7 Correct 222 ms 9196 KB Output is correct
8 Correct 224 ms 9444 KB Output is correct
9 Correct 220 ms 9404 KB Output is correct
10 Correct 203 ms 9072 KB Output is correct
11 Correct 208 ms 9240 KB Output is correct
12 Correct 90 ms 8604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 9452 KB Output is correct
2 Correct 244 ms 9456 KB Output is correct
3 Correct 238 ms 9452 KB Output is correct
4 Correct 204 ms 9332 KB Output is correct
5 Correct 213 ms 9456 KB Output is correct
6 Correct 142 ms 8816 KB Output is correct
7 Correct 222 ms 9196 KB Output is correct
8 Correct 224 ms 9444 KB Output is correct
9 Correct 220 ms 9404 KB Output is correct
10 Correct 203 ms 9072 KB Output is correct
11 Correct 208 ms 9240 KB Output is correct
12 Correct 90 ms 8604 KB Output is correct
13 Correct 373 ms 9796 KB Output is correct
14 Correct 345 ms 9712 KB Output is correct
15 Correct 243 ms 9456 KB Output is correct
16 Correct 319 ms 9472 KB Output is correct
17 Correct 319 ms 9512 KB Output is correct
18 Correct 134 ms 8860 KB Output is correct
19 Correct 356 ms 9832 KB Output is correct
20 Correct 345 ms 9712 KB Output is correct
21 Correct 429 ms 9580 KB Output is correct
22 Correct 189 ms 9072 KB Output is correct
23 Correct 197 ms 9200 KB Output is correct
24 Correct 88 ms 8556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 8 ms 640 KB Output is correct
9 Correct 8 ms 640 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 6 ms 720 KB Output is correct
15 Correct 6 ms 640 KB Output is correct
16 Correct 7 ms 640 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 3 ms 640 KB Output is correct
19 Correct 230 ms 9452 KB Output is correct
20 Correct 244 ms 9456 KB Output is correct
21 Correct 238 ms 9452 KB Output is correct
22 Correct 204 ms 9332 KB Output is correct
23 Correct 213 ms 9456 KB Output is correct
24 Correct 142 ms 8816 KB Output is correct
25 Correct 222 ms 9196 KB Output is correct
26 Correct 224 ms 9444 KB Output is correct
27 Correct 220 ms 9404 KB Output is correct
28 Correct 203 ms 9072 KB Output is correct
29 Correct 208 ms 9240 KB Output is correct
30 Correct 90 ms 8604 KB Output is correct
31 Correct 373 ms 9796 KB Output is correct
32 Correct 345 ms 9712 KB Output is correct
33 Correct 243 ms 9456 KB Output is correct
34 Correct 319 ms 9472 KB Output is correct
35 Correct 319 ms 9512 KB Output is correct
36 Correct 134 ms 8860 KB Output is correct
37 Correct 356 ms 9832 KB Output is correct
38 Correct 345 ms 9712 KB Output is correct
39 Correct 429 ms 9580 KB Output is correct
40 Correct 189 ms 9072 KB Output is correct
41 Correct 197 ms 9200 KB Output is correct
42 Correct 88 ms 8556 KB Output is correct
43 Correct 384 ms 10348 KB Output is correct
44 Correct 384 ms 10608 KB Output is correct
45 Correct 376 ms 10468 KB Output is correct
46 Correct 344 ms 10480 KB Output is correct
47 Correct 341 ms 10352 KB Output is correct
48 Correct 148 ms 8684 KB Output is correct
49 Correct 383 ms 10224 KB Output is correct
50 Correct 383 ms 10488 KB Output is correct
51 Correct 357 ms 10352 KB Output is correct
52 Correct 319 ms 10224 KB Output is correct
53 Correct 196 ms 9456 KB Output is correct