답안 #383734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
383734 2021-03-30T18:29:27 Z aryan12 Examination (JOI19_examination) C++17
100 / 100
421 ms 75636 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

struct marks {
	int x, y, sum, idx;
};

struct tree {
	int l, r, val;
};


const int N = 1e5 + 5;
marks a[N], b[N];
int sz[2] = {1, 1};
tree seg[2][N * 100];

bool cmp(marks A, marks B) {
	return A.sum > B.sum;
}

void Update(int flag, int qpos, int pos, int l, int r) {
	//cout << l << " " << r << "\n";
	if(l == r) {
		//cout << "flag = " << flag << ", " << "qpos = " << qpos << ", pos = " << pos << ", l = " << l << ", r = " << r << "\n";
		seg[flag][pos].val++;
		return;
	}
	int mid = (l + r) >> 1;
	if(mid >= qpos) {
		if(seg[flag][pos].l == 0) {
			seg[flag][pos].l = ++sz[flag];
		}
		Update(flag, qpos, seg[flag][pos].l, l, mid);
	}
	else {
		if(seg[flag][pos].r == 0) {
			seg[flag][pos].r = ++sz[flag];
		}
		Update(flag, qpos, seg[flag][pos].r, mid + 1, r);
	}
	seg[flag][pos].val = seg[flag][seg[flag][pos].l].val + seg[flag][seg[flag][pos].r].val;
}

int Query(int flag, int ql, int qr, int pos, int l, int r) {
	if(ql > r || l > qr || pos == 0 || l > r)
		return 0;
	if(ql <= l && r <= qr) {
		return seg[flag][pos].val;
	}
	int mid = (l + r) >> 1;
	return Query(flag, ql, qr, seg[flag][pos].l, l, mid) + Query(flag, ql, qr, seg[flag][pos].r, mid + 1, r);
}

void Solve() {
	int n, q;
	cin >> n >> q;
	marks temp;
	for(int i = 1; i <= n; i++) {
		cin >> temp.x >> temp.y;
		temp.sum = temp.x + temp.y;
		temp.idx = 0;
		a[i] = temp;
	}
	for(int i = 1; i <= q; i++) {
		cin >> temp.x >> temp.y >> temp.sum;
		temp.sum = max(temp.sum, temp.x + temp.y);
		temp.idx = i;
		b[i] = temp;
	}
	sort(a + 1, a + 1 + n, cmp);
	sort(b + 1, b + 1 + q, cmp);
	int ans[q + 1];
	int aPos = 1;
	for(int i = 1; i <= q; i++) {
		while(aPos != n + 1 && a[aPos].sum >= b[i].sum) {
			Update(0, a[aPos].x, 1, 0, INT_MAX);
			Update(1, a[aPos].y, 1, 0, INT_MAX);
			aPos++;
		}
		ans[b[i].idx] = aPos - 1 - Query(0, 0, b[i].x - 1, 1, 0, INT_MAX) - Query(1, 0, b[i].y - 1, 1, 0, INT_MAX);
	}
	for(int i = 1; i <= q; i++) {
		cout << ans[i] << "\n";
	}
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	Solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 10 ms 3308 KB Output is correct
8 Correct 10 ms 3308 KB Output is correct
9 Correct 10 ms 3308 KB Output is correct
10 Correct 8 ms 2028 KB Output is correct
11 Correct 8 ms 1900 KB Output is correct
12 Correct 6 ms 620 KB Output is correct
13 Correct 10 ms 3308 KB Output is correct
14 Correct 10 ms 3308 KB Output is correct
15 Correct 10 ms 3308 KB Output is correct
16 Correct 7 ms 1900 KB Output is correct
17 Correct 7 ms 1900 KB Output is correct
18 Correct 5 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 292 ms 15340 KB Output is correct
2 Correct 300 ms 15340 KB Output is correct
3 Correct 293 ms 15340 KB Output is correct
4 Correct 209 ms 11756 KB Output is correct
5 Correct 209 ms 11628 KB Output is correct
6 Correct 174 ms 8044 KB Output is correct
7 Correct 281 ms 15340 KB Output is correct
8 Correct 296 ms 15340 KB Output is correct
9 Correct 270 ms 15340 KB Output is correct
10 Correct 194 ms 11500 KB Output is correct
11 Correct 194 ms 11500 KB Output is correct
12 Correct 130 ms 7660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 292 ms 15340 KB Output is correct
2 Correct 300 ms 15340 KB Output is correct
3 Correct 293 ms 15340 KB Output is correct
4 Correct 209 ms 11756 KB Output is correct
5 Correct 209 ms 11628 KB Output is correct
6 Correct 174 ms 8044 KB Output is correct
7 Correct 281 ms 15340 KB Output is correct
8 Correct 296 ms 15340 KB Output is correct
9 Correct 270 ms 15340 KB Output is correct
10 Correct 194 ms 11500 KB Output is correct
11 Correct 194 ms 11500 KB Output is correct
12 Correct 130 ms 7660 KB Output is correct
13 Correct 286 ms 15340 KB Output is correct
14 Correct 292 ms 15340 KB Output is correct
15 Correct 294 ms 15468 KB Output is correct
16 Correct 205 ms 11628 KB Output is correct
17 Correct 207 ms 11788 KB Output is correct
18 Correct 174 ms 8044 KB Output is correct
19 Correct 302 ms 15400 KB Output is correct
20 Correct 280 ms 15340 KB Output is correct
21 Correct 269 ms 15468 KB Output is correct
22 Correct 198 ms 11628 KB Output is correct
23 Correct 196 ms 11500 KB Output is correct
24 Correct 122 ms 7660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 10 ms 3308 KB Output is correct
8 Correct 10 ms 3308 KB Output is correct
9 Correct 10 ms 3308 KB Output is correct
10 Correct 8 ms 2028 KB Output is correct
11 Correct 8 ms 1900 KB Output is correct
12 Correct 6 ms 620 KB Output is correct
13 Correct 10 ms 3308 KB Output is correct
14 Correct 10 ms 3308 KB Output is correct
15 Correct 10 ms 3308 KB Output is correct
16 Correct 7 ms 1900 KB Output is correct
17 Correct 7 ms 1900 KB Output is correct
18 Correct 5 ms 620 KB Output is correct
19 Correct 292 ms 15340 KB Output is correct
20 Correct 300 ms 15340 KB Output is correct
21 Correct 293 ms 15340 KB Output is correct
22 Correct 209 ms 11756 KB Output is correct
23 Correct 209 ms 11628 KB Output is correct
24 Correct 174 ms 8044 KB Output is correct
25 Correct 281 ms 15340 KB Output is correct
26 Correct 296 ms 15340 KB Output is correct
27 Correct 270 ms 15340 KB Output is correct
28 Correct 194 ms 11500 KB Output is correct
29 Correct 194 ms 11500 KB Output is correct
30 Correct 130 ms 7660 KB Output is correct
31 Correct 286 ms 15340 KB Output is correct
32 Correct 292 ms 15340 KB Output is correct
33 Correct 294 ms 15468 KB Output is correct
34 Correct 205 ms 11628 KB Output is correct
35 Correct 207 ms 11788 KB Output is correct
36 Correct 174 ms 8044 KB Output is correct
37 Correct 302 ms 15400 KB Output is correct
38 Correct 280 ms 15340 KB Output is correct
39 Correct 269 ms 15468 KB Output is correct
40 Correct 198 ms 11628 KB Output is correct
41 Correct 196 ms 11500 KB Output is correct
42 Correct 122 ms 7660 KB Output is correct
43 Correct 397 ms 75568 KB Output is correct
44 Correct 392 ms 75500 KB Output is correct
45 Correct 421 ms 75636 KB Output is correct
46 Correct 229 ms 41708 KB Output is correct
47 Correct 229 ms 41580 KB Output is correct
48 Correct 149 ms 7788 KB Output is correct
49 Correct 410 ms 75628 KB Output is correct
50 Correct 383 ms 75628 KB Output is correct
51 Correct 406 ms 75552 KB Output is correct
52 Correct 218 ms 41580 KB Output is correct
53 Correct 219 ms 41580 KB Output is correct