Submission #112267

# Submission time Handle Problem Language Result Execution time Memory
112267 2019-05-18T08:03:25 Z JustInCase Examination (JOI19_examination) C++17
100 / 100
2092 ms 11904 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 8 ms 768 KB Output is correct
8 Correct 10 ms 768 KB Output is correct
9 Correct 10 ms 768 KB Output is correct
10 Correct 9 ms 768 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 9 ms 768 KB Output is correct
14 Correct 10 ms 640 KB Output is correct
15 Correct 10 ms 768 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2050 ms 9336 KB Output is correct
2 Correct 1954 ms 9324 KB Output is correct
3 Correct 1958 ms 9324 KB Output is correct
4 Correct 1240 ms 8588 KB Output is correct
5 Correct 189 ms 8696 KB Output is correct
6 Correct 123 ms 7800 KB Output is correct
7 Correct 555 ms 9228 KB Output is correct
8 Correct 547 ms 9332 KB Output is correct
9 Correct 407 ms 9208 KB Output is correct
10 Correct 126 ms 8476 KB Output is correct
11 Correct 1131 ms 8428 KB Output is correct
12 Correct 66 ms 7032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2050 ms 9336 KB Output is correct
2 Correct 1954 ms 9324 KB Output is correct
3 Correct 1958 ms 9324 KB Output is correct
4 Correct 1240 ms 8588 KB Output is correct
5 Correct 189 ms 8696 KB Output is correct
6 Correct 123 ms 7800 KB Output is correct
7 Correct 555 ms 9228 KB Output is correct
8 Correct 547 ms 9332 KB Output is correct
9 Correct 407 ms 9208 KB Output is correct
10 Correct 126 ms 8476 KB Output is correct
11 Correct 1131 ms 8428 KB Output is correct
12 Correct 66 ms 7032 KB Output is correct
13 Correct 1978 ms 9752 KB Output is correct
14 Correct 2005 ms 9720 KB Output is correct
15 Correct 2092 ms 9384 KB Output is correct
16 Correct 1252 ms 8960 KB Output is correct
17 Correct 215 ms 8952 KB Output is correct
18 Correct 133 ms 7700 KB Output is correct
19 Correct 2001 ms 9848 KB Output is correct
20 Correct 1993 ms 9832 KB Output is correct
21 Correct 1025 ms 9712 KB Output is correct
22 Correct 131 ms 8312 KB Output is correct
23 Correct 1122 ms 8312 KB Output is correct
24 Correct 67 ms 7032 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 8 ms 768 KB Output is correct
8 Correct 10 ms 768 KB Output is correct
9 Correct 10 ms 768 KB Output is correct
10 Correct 9 ms 768 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 9 ms 768 KB Output is correct
14 Correct 10 ms 640 KB Output is correct
15 Correct 10 ms 768 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 2050 ms 9336 KB Output is correct
20 Correct 1954 ms 9324 KB Output is correct
21 Correct 1958 ms 9324 KB Output is correct
22 Correct 1240 ms 8588 KB Output is correct
23 Correct 189 ms 8696 KB Output is correct
24 Correct 123 ms 7800 KB Output is correct
25 Correct 555 ms 9228 KB Output is correct
26 Correct 547 ms 9332 KB Output is correct
27 Correct 407 ms 9208 KB Output is correct
28 Correct 126 ms 8476 KB Output is correct
29 Correct 1131 ms 8428 KB Output is correct
30 Correct 66 ms 7032 KB Output is correct
31 Correct 1978 ms 9752 KB Output is correct
32 Correct 2005 ms 9720 KB Output is correct
33 Correct 2092 ms 9384 KB Output is correct
34 Correct 1252 ms 8960 KB Output is correct
35 Correct 215 ms 8952 KB Output is correct
36 Correct 133 ms 7700 KB Output is correct
37 Correct 2001 ms 9848 KB Output is correct
38 Correct 1993 ms 9832 KB Output is correct
39 Correct 1025 ms 9712 KB Output is correct
40 Correct 131 ms 8312 KB Output is correct
41 Correct 1122 ms 8312 KB Output is correct
42 Correct 67 ms 7032 KB Output is correct
43 Correct 2004 ms 11904 KB Output is correct
44 Correct 2074 ms 11804 KB Output is correct
45 Correct 2068 ms 11768 KB Output is correct
46 Correct 1256 ms 10100 KB Output is correct
47 Correct 217 ms 10104 KB Output is correct
48 Correct 128 ms 7416 KB Output is correct
49 Correct 600 ms 11680 KB Output is correct
50 Correct 584 ms 11640 KB Output is correct
51 Correct 442 ms 11456 KB Output is correct
52 Correct 156 ms 10044 KB Output is correct
53 Correct 1131 ms 9196 KB Output is correct