Submission #981579

# Submission time Handle Problem Language Result Execution time Memory
981579 2024-05-13T10:57:57 Z josanneo22 Examination (JOI19_examination) C++17
100 / 100
1446 ms 12124 KB
#pragma GCC optimize("O3")

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

const int nax = 100005;
const int BLOCK = 317;

struct query {
	int a, b, c, id;
	bool operator < (const query& o) const {
		int F = a / BLOCK;
		int S = o.a / BLOCK;
		if (F == S) return b < o.b;
		return F < S;
	}
};

#define low(x) x & -x
struct fenw {
	vector<i64> T;
	int _N;

	fenw(int N) {
		_N = N;
		T.assign(_N + 500, 0);
	}
	void update(int p, int x) {
		int P = p;
		while (P <= _N) {
			T[P] += x;
			P += low(P);
		}
	}
	int query(int x) {
		int P = x, res = 0;
		while (P >= 1) {
			res += T[P];
			P -= low(P);
		}
		return res;
	}
};

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

	int N, Q;
	cin >> N >> Q;

	vector<int> A(N), B(N), C(N), CC(N);
	vector<pair<int, int>> AA(N), BB(N);

	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
		AA[i] = make_pair(A[i], i);
		BB[i] = make_pair(B[i], i);
		CC[i] = A[i] + B[i];
		C[i] = A[i] + B[i];
	}

	sort(AA.begin(), AA.end());
	sort(BB.begin(), BB.end());

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	for (int i = 0; i < N; i++) {
		AA[i].first = lower_bound(A.begin(), A.end(), AA[i].first) - A.begin();
		BB[i].first = lower_bound(B.begin(), B.end(), BB[i].first) - B.begin();
		CC[i] = lower_bound(C.begin(), C.end(), CC[i]) - C.begin();
	}

	vector<query> que(Q);
	for (int i = 0; i < Q; i++) {
		cin >> que[i].a >> que[i].b >> que[i].c;
		que[i].a = lower_bound(A.begin(), A.end(), que[i].a) - A.begin();
		que[i].b = lower_bound(B.begin(), B.end(), que[i].b) - B.begin();
		que[i].c = lower_bound(C.begin(), C.end(), que[i].c) - C.begin();
		que[i].id = i;
	}
	sort(que.begin(), que.end());

	vector<int> cnt(N), ans(Q);
	fenw fen(N);
	int L = N - 1, R = N - 1;
	for (int i = 0; i < Q; i++) {
		while (L >= que[i].a) {
			if (++cnt[AA[L].second] == 2)
				fen.update(CC[AA[L].second] + 1, +1);
			L--;
		}
		while (R >= que[i].b) {
			if (++cnt[BB[R].second] == 2)
				fen.update(CC[BB[R].second] + 1, +1);
			R--;
		}
		while (L + 1 < que[i].a) {
			L++;
			if (--cnt[AA[L].second] == 1)
				fen.update(CC[AA[L].second] + 1, -1);
		}
		while (R + 1 < que[i].b) {
			R++;
			if (--cnt[BB[R].second] == 1)
				fen.update(CC[BB[R].second] + 1, -1);
		}
		ans[que[i].id] = fen.query(N) - fen.query(que[i].c);
	}

	for (int i = 0; i < Q; i++) {
		cout << ans[i] << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 7 ms 604 KB Output is correct
8 Correct 7 ms 796 KB Output is correct
9 Correct 7 ms 856 KB Output is correct
10 Correct 6 ms 748 KB Output is correct
11 Correct 5 ms 724 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 6 ms 772 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 8 ms 604 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 5 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1371 ms 9740 KB Output is correct
2 Correct 1356 ms 9812 KB Output is correct
3 Correct 1381 ms 9736 KB Output is correct
4 Correct 1022 ms 9212 KB Output is correct
5 Correct 157 ms 9044 KB Output is correct
6 Correct 100 ms 8276 KB Output is correct
7 Correct 392 ms 9636 KB Output is correct
8 Correct 404 ms 9552 KB Output is correct
9 Correct 308 ms 9456 KB Output is correct
10 Correct 99 ms 8784 KB Output is correct
11 Correct 1045 ms 8832 KB Output is correct
12 Correct 54 ms 7760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1371 ms 9740 KB Output is correct
2 Correct 1356 ms 9812 KB Output is correct
3 Correct 1381 ms 9736 KB Output is correct
4 Correct 1022 ms 9212 KB Output is correct
5 Correct 157 ms 9044 KB Output is correct
6 Correct 100 ms 8276 KB Output is correct
7 Correct 392 ms 9636 KB Output is correct
8 Correct 404 ms 9552 KB Output is correct
9 Correct 308 ms 9456 KB Output is correct
10 Correct 99 ms 8784 KB Output is correct
11 Correct 1045 ms 8832 KB Output is correct
12 Correct 54 ms 7760 KB Output is correct
13 Correct 1446 ms 10192 KB Output is correct
14 Correct 1376 ms 10112 KB Output is correct
15 Correct 1353 ms 9556 KB Output is correct
16 Correct 1036 ms 9556 KB Output is correct
17 Correct 163 ms 9520 KB Output is correct
18 Correct 104 ms 8272 KB Output is correct
19 Correct 1381 ms 10168 KB Output is correct
20 Correct 1401 ms 10020 KB Output is correct
21 Correct 702 ms 10152 KB Output is correct
22 Correct 99 ms 8684 KB Output is correct
23 Correct 1030 ms 8720 KB Output is correct
24 Correct 54 ms 7760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 7 ms 604 KB Output is correct
8 Correct 7 ms 796 KB Output is correct
9 Correct 7 ms 856 KB Output is correct
10 Correct 6 ms 748 KB Output is correct
11 Correct 5 ms 724 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 6 ms 772 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 8 ms 604 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 5 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1371 ms 9740 KB Output is correct
20 Correct 1356 ms 9812 KB Output is correct
21 Correct 1381 ms 9736 KB Output is correct
22 Correct 1022 ms 9212 KB Output is correct
23 Correct 157 ms 9044 KB Output is correct
24 Correct 100 ms 8276 KB Output is correct
25 Correct 392 ms 9636 KB Output is correct
26 Correct 404 ms 9552 KB Output is correct
27 Correct 308 ms 9456 KB Output is correct
28 Correct 99 ms 8784 KB Output is correct
29 Correct 1045 ms 8832 KB Output is correct
30 Correct 54 ms 7760 KB Output is correct
31 Correct 1446 ms 10192 KB Output is correct
32 Correct 1376 ms 10112 KB Output is correct
33 Correct 1353 ms 9556 KB Output is correct
34 Correct 1036 ms 9556 KB Output is correct
35 Correct 163 ms 9520 KB Output is correct
36 Correct 104 ms 8272 KB Output is correct
37 Correct 1381 ms 10168 KB Output is correct
38 Correct 1401 ms 10020 KB Output is correct
39 Correct 702 ms 10152 KB Output is correct
40 Correct 99 ms 8684 KB Output is correct
41 Correct 1030 ms 8720 KB Output is correct
42 Correct 54 ms 7760 KB Output is correct
43 Correct 1399 ms 12124 KB Output is correct
44 Correct 1389 ms 12124 KB Output is correct
45 Correct 1366 ms 12072 KB Output is correct
46 Correct 1031 ms 10556 KB Output is correct
47 Correct 159 ms 10548 KB Output is correct
48 Correct 103 ms 8020 KB Output is correct
49 Correct 425 ms 11972 KB Output is correct
50 Correct 429 ms 11904 KB Output is correct
51 Correct 342 ms 12096 KB Output is correct
52 Correct 119 ms 10324 KB Output is correct
53 Correct 1024 ms 9552 KB Output is correct