Submission #123683

# Submission time Handle Problem Language Result Execution time Memory
123683 2019-07-02T03:57:42 Z 윤교준(#3030) Examination (JOI19_examination) C++14
100 / 100
571 ms 22688 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
using namespace std;

const int MAXN = 100055;
const int MAXQ = 100055;

struct DYBIT {
	DYBIT(int _n) : n(_n) { d = new int[_n+1]; memset(d, 0, (_n+1)<<2); }
	const int n;
	int *d;
	void upd(int x, int r) {
		for(x++; x <= n; x += rb(x))
			d[x] += r;
	}
	int get(int x) {
		int r = 0; for(x++; x; x -= rb(x))
			r += d[x];
		return r;
	}
};

struct BIT {
	vector<int> V[MAXN];
	DYBIT *d[MAXN];

	void precal() {
		for(int i = 1; i < MAXN; i++) {
			if(V[i].empty()) continue;
			sorv(V[i]); univ(V[i]);
			d[i] = new DYBIT(sz(V[i]));
		}
	}
	void push(int x, int y) {
		for(x++; x < MAXN; x += rb(x))
			V[x].eb(y);
	}
	void upd(int x, int y, int r) {
		for(x++; x < MAXN; x += rb(x)) {
			int yi = int(lower_bound(allv(V[x]), y) - V[x].begin());
			d[x]->upd(yi, r);
		}
	}
	int get(int x, int y) {
		int r = 0; for(x++; x; x -= rb(x)) {
			int yi = int(upper_bound(allv(V[x]), y) - V[x].begin()) - 1;
			if(0 <= yi) r += d[x]->get(yi);
		}
		return r;
	}
} bit;

int O[MAXN], QO[MAXQ];

vector<int> VX;
int A[MAXN], B[MAXN];
int C[MAXQ], D[MAXQ], E[MAXQ];

int Ans[MAXQ];
int N, Q;

bool cmp(int i, int qi) {
	return E[qi] <= A[i] + B[i];
}

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> Q;
	for(int i = 1; i <= N; i++) cin >> A[i] >> B[i];
	for(int i = 1; i <= Q; i++) cin >> C[i] >> D[i] >> E[i];

	iota(O, O+N+1, 0); iota(QO, QO+Q+1, 0);
	sort(O+1, O+N+1, [&](int a, int b) {
		return A[a]+B[a] > A[b]+B[b];
	});
	sort(QO+1, QO+Q+1, [&](int a, int b) {
		return E[a] > E[b];
	});

	for(int i = 1; i <= N; i++) VX.eb(INF-A[i]);
	sorv(VX); univ(VX);
	for(int i = 1; i <= N; i++)
		bit.push(int(lower_bound(allv(VX), INF-A[i]) - VX.begin()), INF-B[i]);
	bit.precal();
	
	for(int qoi = 1, oi = 1; qoi <= Q; qoi++) {
		for(int i; oi <= N && cmp(O[oi], QO[qoi]); oi++) {
			i = O[oi];
			bit.upd(int(lower_bound(allv(VX), INF-A[i])-VX.begin()), INF-B[i], 1);
		}
		int idx = QO[qoi];
		int xi = int(upper_bound(allv(VX), INF-C[idx]) - VX.begin()) - 1;
		if(0 <= xi) Ans[idx] = bit.get(xi, INF-D[idx]);
	}

	for(int i = 1; i <= Q; i++) printf("%d\n", Ans[i]);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2808 KB Output is correct
2 Correct 4 ms 2808 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2808 KB Output is correct
5 Correct 4 ms 2808 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Correct 15 ms 3448 KB Output is correct
8 Correct 15 ms 3476 KB Output is correct
9 Correct 15 ms 3448 KB Output is correct
10 Correct 11 ms 3320 KB Output is correct
11 Correct 13 ms 3320 KB Output is correct
12 Correct 8 ms 3192 KB Output is correct
13 Correct 14 ms 3448 KB Output is correct
14 Correct 14 ms 3448 KB Output is correct
15 Correct 14 ms 3448 KB Output is correct
16 Correct 12 ms 3452 KB Output is correct
17 Correct 9 ms 3320 KB Output is correct
18 Correct 7 ms 3192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 483 ms 19604 KB Output is correct
2 Correct 488 ms 19616 KB Output is correct
3 Correct 499 ms 19572 KB Output is correct
4 Correct 252 ms 17012 KB Output is correct
5 Correct 365 ms 18164 KB Output is correct
6 Correct 167 ms 14580 KB Output is correct
7 Correct 480 ms 19592 KB Output is correct
8 Correct 461 ms 19652 KB Output is correct
9 Correct 447 ms 19700 KB Output is correct
10 Correct 341 ms 18660 KB Output is correct
11 Correct 202 ms 16664 KB Output is correct
12 Correct 112 ms 15036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 483 ms 19604 KB Output is correct
2 Correct 488 ms 19616 KB Output is correct
3 Correct 499 ms 19572 KB Output is correct
4 Correct 252 ms 17012 KB Output is correct
5 Correct 365 ms 18164 KB Output is correct
6 Correct 167 ms 14580 KB Output is correct
7 Correct 480 ms 19592 KB Output is correct
8 Correct 461 ms 19652 KB Output is correct
9 Correct 447 ms 19700 KB Output is correct
10 Correct 341 ms 18660 KB Output is correct
11 Correct 202 ms 16664 KB Output is correct
12 Correct 112 ms 15036 KB Output is correct
13 Correct 541 ms 19644 KB Output is correct
14 Correct 532 ms 19696 KB Output is correct
15 Correct 489 ms 19616 KB Output is correct
16 Correct 324 ms 17112 KB Output is correct
17 Correct 389 ms 18420 KB Output is correct
18 Correct 167 ms 14940 KB Output is correct
19 Correct 548 ms 19564 KB Output is correct
20 Correct 534 ms 19520 KB Output is correct
21 Correct 523 ms 19700 KB Output is correct
22 Correct 343 ms 18684 KB Output is correct
23 Correct 211 ms 16756 KB Output is correct
24 Correct 113 ms 15220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2808 KB Output is correct
2 Correct 4 ms 2808 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2808 KB Output is correct
5 Correct 4 ms 2808 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Correct 15 ms 3448 KB Output is correct
8 Correct 15 ms 3476 KB Output is correct
9 Correct 15 ms 3448 KB Output is correct
10 Correct 11 ms 3320 KB Output is correct
11 Correct 13 ms 3320 KB Output is correct
12 Correct 8 ms 3192 KB Output is correct
13 Correct 14 ms 3448 KB Output is correct
14 Correct 14 ms 3448 KB Output is correct
15 Correct 14 ms 3448 KB Output is correct
16 Correct 12 ms 3452 KB Output is correct
17 Correct 9 ms 3320 KB Output is correct
18 Correct 7 ms 3192 KB Output is correct
19 Correct 483 ms 19604 KB Output is correct
20 Correct 488 ms 19616 KB Output is correct
21 Correct 499 ms 19572 KB Output is correct
22 Correct 252 ms 17012 KB Output is correct
23 Correct 365 ms 18164 KB Output is correct
24 Correct 167 ms 14580 KB Output is correct
25 Correct 480 ms 19592 KB Output is correct
26 Correct 461 ms 19652 KB Output is correct
27 Correct 447 ms 19700 KB Output is correct
28 Correct 341 ms 18660 KB Output is correct
29 Correct 202 ms 16664 KB Output is correct
30 Correct 112 ms 15036 KB Output is correct
31 Correct 541 ms 19644 KB Output is correct
32 Correct 532 ms 19696 KB Output is correct
33 Correct 489 ms 19616 KB Output is correct
34 Correct 324 ms 17112 KB Output is correct
35 Correct 389 ms 18420 KB Output is correct
36 Correct 167 ms 14940 KB Output is correct
37 Correct 548 ms 19564 KB Output is correct
38 Correct 534 ms 19520 KB Output is correct
39 Correct 523 ms 19700 KB Output is correct
40 Correct 343 ms 18684 KB Output is correct
41 Correct 211 ms 16756 KB Output is correct
42 Correct 113 ms 15220 KB Output is correct
43 Correct 561 ms 22688 KB Output is correct
44 Correct 571 ms 22592 KB Output is correct
45 Correct 561 ms 22460 KB Output is correct
46 Correct 306 ms 20024 KB Output is correct
47 Correct 416 ms 20316 KB Output is correct
48 Correct 171 ms 14196 KB Output is correct
49 Correct 536 ms 22616 KB Output is correct
50 Correct 547 ms 22360 KB Output is correct
51 Correct 515 ms 22380 KB Output is correct
52 Correct 396 ms 21160 KB Output is correct
53 Correct 243 ms 19708 KB Output is correct