Submission #102243

# Submission time Handle Problem Language Result Execution time Memory
102243 2019-03-23T20:17:33 Z JustInCase Examination (JOI19_examination) C++17
100 / 100
2246 ms 7592 KB
#include <bits/stdc++.h>

const int32_t MAX_N = 1e5;
const int32_t MAX_Q = 1e5;
const int32_t BUCKET_SIZE = 316;

struct Query {
	int32_t a, b, c, ind;
	
	bool operator< (const Query &o) const {
		int32_t bucket = a / BUCKET_SIZE;
		int32_t oBucket = o.a / BUCKET_SIZE;

		if(bucket == oBucket) {
			return b < o.b;
		}

		return bucket < oBucket;
	}
};

struct IndexTree {
	int32_t treeSize;
	int32_t data[2 * MAX_N + 5];

	void init(int32_t _treeSize) {
		treeSize = _treeSize;
	}

	void update(int32_t ind, int32_t val) {
		while(ind <= treeSize) {
			data[ind] += val;
			ind += (ind & (-ind));
		}
	}

	int32_t query(int32_t ind) {
		int32_t ans = 0;

		while(ind >= 1) {
			ans += data[ind];
			ind -= (ind & (-ind));
		}

		return ans;
	}
};

int32_t allAs[MAX_N + 5], allBs[MAX_N + 5], allCs[MAX_N + 5], newCs[MAX_N + 5], c[MAX_N + 5];
int32_t cnt[MAX_N + 5], ans[MAX_Q + 5];
std::pair< int32_t, int32_t > a[MAX_N + 5], b[MAX_N + 5];
Query qs[MAX_Q + 5];
IndexTree indTree;

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int32_t n, q;
	std::cin >> n >> q;

	for(int32_t i = 0; i < n; i++) {
		std::cin >> a[i].first >> b[i].first;

		allAs[i] = a[i].first;
		a[i].second = i;

		allBs[i] = b[i].first;
		b[i].second = i;
		
		c[i] = a[i].first + b[i].first;
		allCs[i] = a[i].first + b[i].first;
	}

	std::sort(allAs, allAs + n);
	std::sort(a, a + n);
	std::sort(allBs, allBs + n);
	std::sort(b, b + n);
	std::sort(allCs, allCs + n);
	
	for(int32_t i = 0; i < n; i++) {
		a[i].first = std::lower_bound(allAs, allAs + n, a[i].first) - allAs;
		b[i].first = std::lower_bound(allBs, allBs + n, b[i].first) - allBs;
		c[i] = std::lower_bound(allCs, allCs + n, c[i]) - allCs;
	}

	for(int32_t i = 0; i < q; i++) {
		int32_t u, v, t;
		std::cin >> u >> v >> t;
		
		qs[i].a = std::lower_bound(allAs, allAs + n, u) - allAs;
		qs[i].b = std::lower_bound(allBs, allBs + n, v) - allBs;
		qs[i].c = std::lower_bound(allCs, allCs + n, t) - allCs;
		qs[i].ind = i;
	}
	std::sort(qs, qs + q);

	indTree.init(n);
	int32_t indA = n - 1, indB = n - 1;
	for(int32_t i = 0; i < q; i++) {
		while(indA >= qs[i].a) {
			cnt[a[indA].second]++;
			if(cnt[a[indA].second] == 2) {
				indTree.update(c[a[indA].second] + 1, 1);
			}

			indA--;
		}

		while(indA + 1 < qs[i].a) {
			indA++;
			
			cnt[a[indA].second]--;
			if(cnt[a[indA].second] == 1) {
				indTree.update(c[a[indA].second] + 1, -1);
			}
		}

		while(indB >= qs[i].b) {
			cnt[b[indB].second]++;

			if(cnt[b[indB].second] == 2) {
				indTree.update(c[b[indB].second] + 1, 1);
			}

			indB--;
		}

		while(indB + 1 < qs[i].b) {
			indB++;
			
			cnt[b[indB].second]--;
			if(cnt[b[indB].second] == 1) {
				indTree.update(c[b[indB].second] + 1, -1);
			}
		}

		ans[qs[i].ind] = indTree.query(indTree.treeSize) - indTree.query(qs[i].c);
	}

	for(int32_t i = 0; i < q; i++) {
		std::cout << ans[i] << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 10 ms 640 KB Output is correct
8 Correct 10 ms 768 KB Output is correct
9 Correct 10 ms 640 KB Output is correct
10 Correct 10 ms 616 KB Output is correct
11 Correct 8 ms 640 KB Output is correct
12 Correct 7 ms 512 KB Output is correct
13 Correct 10 ms 640 KB Output is correct
14 Correct 9 ms 768 KB Output is correct
15 Correct 10 ms 768 KB Output is correct
16 Correct 6 ms 588 KB Output is correct
17 Correct 8 ms 640 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2087 ms 7424 KB Output is correct
2 Correct 2035 ms 7444 KB Output is correct
3 Correct 2094 ms 7532 KB Output is correct
4 Correct 1245 ms 7592 KB Output is correct
5 Correct 195 ms 7416 KB Output is correct
6 Correct 149 ms 7160 KB Output is correct
7 Correct 577 ms 7464 KB Output is correct
8 Correct 578 ms 7544 KB Output is correct
9 Correct 410 ms 7416 KB Output is correct
10 Correct 128 ms 7160 KB Output is correct
11 Correct 1116 ms 7376 KB Output is correct
12 Correct 74 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2087 ms 7424 KB Output is correct
2 Correct 2035 ms 7444 KB Output is correct
3 Correct 2094 ms 7532 KB Output is correct
4 Correct 1245 ms 7592 KB Output is correct
5 Correct 195 ms 7416 KB Output is correct
6 Correct 149 ms 7160 KB Output is correct
7 Correct 577 ms 7464 KB Output is correct
8 Correct 578 ms 7544 KB Output is correct
9 Correct 410 ms 7416 KB Output is correct
10 Correct 128 ms 7160 KB Output is correct
11 Correct 1116 ms 7376 KB Output is correct
12 Correct 74 ms 6648 KB Output is correct
13 Correct 2078 ms 7420 KB Output is correct
14 Correct 2066 ms 7436 KB Output is correct
15 Correct 2054 ms 7544 KB Output is correct
16 Correct 1349 ms 7272 KB Output is correct
17 Correct 212 ms 7396 KB Output is correct
18 Correct 132 ms 7004 KB Output is correct
19 Correct 2187 ms 7260 KB Output is correct
20 Correct 2067 ms 7316 KB Output is correct
21 Correct 1034 ms 7344 KB Output is correct
22 Correct 132 ms 7164 KB Output is correct
23 Correct 1156 ms 7160 KB Output is correct
24 Correct 66 ms 6524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 10 ms 640 KB Output is correct
8 Correct 10 ms 768 KB Output is correct
9 Correct 10 ms 640 KB Output is correct
10 Correct 10 ms 616 KB Output is correct
11 Correct 8 ms 640 KB Output is correct
12 Correct 7 ms 512 KB Output is correct
13 Correct 10 ms 640 KB Output is correct
14 Correct 9 ms 768 KB Output is correct
15 Correct 10 ms 768 KB Output is correct
16 Correct 6 ms 588 KB Output is correct
17 Correct 8 ms 640 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 2087 ms 7424 KB Output is correct
20 Correct 2035 ms 7444 KB Output is correct
21 Correct 2094 ms 7532 KB Output is correct
22 Correct 1245 ms 7592 KB Output is correct
23 Correct 195 ms 7416 KB Output is correct
24 Correct 149 ms 7160 KB Output is correct
25 Correct 577 ms 7464 KB Output is correct
26 Correct 578 ms 7544 KB Output is correct
27 Correct 410 ms 7416 KB Output is correct
28 Correct 128 ms 7160 KB Output is correct
29 Correct 1116 ms 7376 KB Output is correct
30 Correct 74 ms 6648 KB Output is correct
31 Correct 2078 ms 7420 KB Output is correct
32 Correct 2066 ms 7436 KB Output is correct
33 Correct 2054 ms 7544 KB Output is correct
34 Correct 1349 ms 7272 KB Output is correct
35 Correct 212 ms 7396 KB Output is correct
36 Correct 132 ms 7004 KB Output is correct
37 Correct 2187 ms 7260 KB Output is correct
38 Correct 2067 ms 7316 KB Output is correct
39 Correct 1034 ms 7344 KB Output is correct
40 Correct 132 ms 7164 KB Output is correct
41 Correct 1156 ms 7160 KB Output is correct
42 Correct 66 ms 6524 KB Output is correct
43 Correct 2122 ms 7336 KB Output is correct
44 Correct 2009 ms 7316 KB Output is correct
45 Correct 2246 ms 7352 KB Output is correct
46 Correct 1390 ms 7360 KB Output is correct
47 Correct 243 ms 7356 KB Output is correct
48 Correct 138 ms 6904 KB Output is correct
49 Correct 718 ms 7416 KB Output is correct
50 Correct 661 ms 7444 KB Output is correct
51 Correct 468 ms 7416 KB Output is correct
52 Correct 168 ms 7160 KB Output is correct
53 Correct 1187 ms 7260 KB Output is correct