답안 #383733

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
383733 2021-03-30T18:28:59 Z aryan12 Examination (JOI19_examination) C++17
100 / 100
433 ms 80620 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 * 400];

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 1 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 1900 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 299 ms 15468 KB Output is correct
2 Correct 310 ms 15468 KB Output is correct
3 Correct 301 ms 15340 KB Output is correct
4 Correct 207 ms 11628 KB Output is correct
5 Correct 210 ms 11628 KB Output is correct
6 Correct 175 ms 8044 KB Output is correct
7 Correct 289 ms 15372 KB Output is correct
8 Correct 278 ms 15340 KB Output is correct
9 Correct 295 ms 15372 KB Output is correct
10 Correct 194 ms 11628 KB Output is correct
11 Correct 194 ms 11500 KB Output is correct
12 Correct 122 ms 7660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 299 ms 15468 KB Output is correct
2 Correct 310 ms 15468 KB Output is correct
3 Correct 301 ms 15340 KB Output is correct
4 Correct 207 ms 11628 KB Output is correct
5 Correct 210 ms 11628 KB Output is correct
6 Correct 175 ms 8044 KB Output is correct
7 Correct 289 ms 15372 KB Output is correct
8 Correct 278 ms 15340 KB Output is correct
9 Correct 295 ms 15372 KB Output is correct
10 Correct 194 ms 11628 KB Output is correct
11 Correct 194 ms 11500 KB Output is correct
12 Correct 122 ms 7660 KB Output is correct
13 Correct 291 ms 15340 KB Output is correct
14 Correct 306 ms 15340 KB Output is correct
15 Correct 289 ms 15468 KB Output is correct
16 Correct 203 ms 11628 KB Output is correct
17 Correct 203 ms 11756 KB Output is correct
18 Correct 178 ms 8044 KB Output is correct
19 Correct 272 ms 15212 KB Output is correct
20 Correct 319 ms 15276 KB Output is correct
21 Correct 288 ms 15340 KB Output is correct
22 Correct 203 ms 11628 KB Output is correct
23 Correct 194 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 1 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 1900 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 299 ms 15468 KB Output is correct
20 Correct 310 ms 15468 KB Output is correct
21 Correct 301 ms 15340 KB Output is correct
22 Correct 207 ms 11628 KB Output is correct
23 Correct 210 ms 11628 KB Output is correct
24 Correct 175 ms 8044 KB Output is correct
25 Correct 289 ms 15372 KB Output is correct
26 Correct 278 ms 15340 KB Output is correct
27 Correct 295 ms 15372 KB Output is correct
28 Correct 194 ms 11628 KB Output is correct
29 Correct 194 ms 11500 KB Output is correct
30 Correct 122 ms 7660 KB Output is correct
31 Correct 291 ms 15340 KB Output is correct
32 Correct 306 ms 15340 KB Output is correct
33 Correct 289 ms 15468 KB Output is correct
34 Correct 203 ms 11628 KB Output is correct
35 Correct 203 ms 11756 KB Output is correct
36 Correct 178 ms 8044 KB Output is correct
37 Correct 272 ms 15212 KB Output is correct
38 Correct 319 ms 15276 KB Output is correct
39 Correct 288 ms 15340 KB Output is correct
40 Correct 203 ms 11628 KB Output is correct
41 Correct 194 ms 11500 KB Output is correct
42 Correct 122 ms 7660 KB Output is correct
43 Correct 387 ms 75500 KB Output is correct
44 Correct 402 ms 80620 KB Output is correct
45 Correct 433 ms 80440 KB Output is correct
46 Correct 233 ms 45164 KB Output is correct
47 Correct 229 ms 44960 KB Output is correct
48 Correct 153 ms 8812 KB Output is correct
49 Correct 426 ms 80492 KB Output is correct
50 Correct 387 ms 80364 KB Output is correct
51 Correct 400 ms 80236 KB Output is correct
52 Correct 221 ms 45036 KB Output is correct
53 Correct 223 ms 44268 KB Output is correct