Submission #383732

# Submission time Handle Problem Language Result Execution time Memory
383732 2021-03-30T18:23:35 Z aryan12 Examination (JOI19_examination) C++17
43 / 100
315 ms 57708 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 * 4];

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;
}
# Verdict Execution time Memory 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 9 ms 3308 KB Output is correct
8 Correct 9 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 13 ms 3308 KB Output is correct
16 Correct 9 ms 1900 KB Output is correct
17 Correct 8 ms 2032 KB Output is correct
18 Correct 4 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 16492 KB Output is correct
2 Correct 299 ms 17900 KB Output is correct
3 Correct 315 ms 17772 KB Output is correct
4 Correct 210 ms 13420 KB Output is correct
5 Correct 220 ms 13548 KB Output is correct
6 Correct 181 ms 8996 KB Output is correct
7 Correct 284 ms 17772 KB Output is correct
8 Correct 280 ms 17784 KB Output is correct
9 Correct 284 ms 17772 KB Output is correct
10 Correct 194 ms 13164 KB Output is correct
11 Correct 200 ms 13252 KB Output is correct
12 Correct 124 ms 8556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 16492 KB Output is correct
2 Correct 299 ms 17900 KB Output is correct
3 Correct 315 ms 17772 KB Output is correct
4 Correct 210 ms 13420 KB Output is correct
5 Correct 220 ms 13548 KB Output is correct
6 Correct 181 ms 8996 KB Output is correct
7 Correct 284 ms 17772 KB Output is correct
8 Correct 280 ms 17784 KB Output is correct
9 Correct 284 ms 17772 KB Output is correct
10 Correct 194 ms 13164 KB Output is correct
11 Correct 200 ms 13252 KB Output is correct
12 Correct 124 ms 8556 KB Output is correct
13 Correct 273 ms 18156 KB Output is correct
14 Correct 305 ms 18284 KB Output is correct
15 Correct 285 ms 17900 KB Output is correct
16 Correct 205 ms 13808 KB Output is correct
17 Correct 204 ms 13804 KB Output is correct
18 Correct 177 ms 9068 KB Output is correct
19 Correct 282 ms 18296 KB Output is correct
20 Correct 298 ms 18156 KB Output is correct
21 Correct 291 ms 18412 KB Output is correct
22 Correct 211 ms 13292 KB Output is correct
23 Correct 197 ms 13292 KB Output is correct
24 Correct 123 ms 8556 KB Output is correct
# Verdict Execution time Memory 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 9 ms 3308 KB Output is correct
8 Correct 9 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 13 ms 3308 KB Output is correct
16 Correct 9 ms 1900 KB Output is correct
17 Correct 8 ms 2032 KB Output is correct
18 Correct 4 ms 620 KB Output is correct
19 Correct 304 ms 16492 KB Output is correct
20 Correct 299 ms 17900 KB Output is correct
21 Correct 315 ms 17772 KB Output is correct
22 Correct 210 ms 13420 KB Output is correct
23 Correct 220 ms 13548 KB Output is correct
24 Correct 181 ms 8996 KB Output is correct
25 Correct 284 ms 17772 KB Output is correct
26 Correct 280 ms 17784 KB Output is correct
27 Correct 284 ms 17772 KB Output is correct
28 Correct 194 ms 13164 KB Output is correct
29 Correct 200 ms 13252 KB Output is correct
30 Correct 124 ms 8556 KB Output is correct
31 Correct 273 ms 18156 KB Output is correct
32 Correct 305 ms 18284 KB Output is correct
33 Correct 285 ms 17900 KB Output is correct
34 Correct 205 ms 13808 KB Output is correct
35 Correct 204 ms 13804 KB Output is correct
36 Correct 177 ms 9068 KB Output is correct
37 Correct 282 ms 18296 KB Output is correct
38 Correct 298 ms 18156 KB Output is correct
39 Correct 291 ms 18412 KB Output is correct
40 Correct 211 ms 13292 KB Output is correct
41 Correct 197 ms 13292 KB Output is correct
42 Correct 123 ms 8556 KB Output is correct
43 Runtime error 204 ms 57708 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -