Submission #383775

# Submission time Handle Problem Language Result Execution time Memory
383775 2021-03-30T19:43:32 Z wind_reaper Examination (JOI19_examination) C++17
100 / 100
204 ms 7660 KB
#include <bits/stdc++.h>

using namespace std;

struct BIT{
	vector<int> tree;
	int N;
	void init(int _n){
		N = _n;
		tree.resize(N+1);
	}
	void upd(int pos, int val){
		for(++pos; pos <= N; pos += (pos & (-pos)))
			tree[pos] += val;
	}
	int que(int idx){
		int sum = 0;
		for(idx++; idx > 0; idx -= (idx & (-idx)))
			sum += tree[idx];
		return sum;
	}
};

int32_t main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	
	int n, q;
	cin >> n >> q;

	vector<array<int, 4>> marks(n), query(q);
	vector<int> ds(n+q), dt(n+q);
	vector<BIT> ft(2);

	for(int i = 0; i < n; i++){
		auto& [tot, s, t, idx] = marks[i];
		cin >> s >> t;
		tot = s + t;
		idx = i;
		ds[i] = s;
		dt[i] = t;
	}
	for(int i = 0; i < q; i++){
		auto& [tot, s, t, idx] = query[i];
		cin >> s >> t >> tot;
		tot = max(tot, s + t);
		idx = i;
		ds[i+n] = s;
		dt[i+n] = t;
	}

	sort(ds.begin(), ds.end());
	ds.erase(unique(ds.begin(), ds.end()), ds.end());
	sort(dt.begin(), dt.end());
	dt.erase(unique(dt.begin(), dt.end()), dt.end());

	ft[0].init(ds.size());
	ft[1].init(dt.size());

	for(auto& [tot, s, t, idx] : marks){
		s = lower_bound(ds.begin(), ds.end(), s) - ds.begin();
		t = lower_bound(dt.begin(), dt.end(), t) - dt.begin();
		assert(s < (n+q) && t < (n+q));
	}

	for(auto& [tot, s, t, idx] : query){
		s = lower_bound(ds.begin(), ds.end(), s) - ds.begin();
		t = lower_bound(dt.begin(), dt.end(), t) - dt.begin();
		assert(s < (n+q) && t < (n+q));
	}

	sort(marks.rbegin(), marks.rend());
	sort(query.rbegin(), query.rend());

	vector<int> ans(q);

	int idx = 0;
	for(int i = 0; i < q; i++){
		while(idx < n && marks[idx][0] >= query[i][0]){
			ft[0].upd(marks[idx][1], 1);
			ft[1].upd(marks[idx][2], 1);
			idx++;
		}
		ans[query[i][3]] = idx - ft[0].que(query[i][1]-1) - ft[1].que(query[i][2]-1);
	}

	for(int i = 0; i < q; i++)
		cout << ans[i] << '\n';
	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 6 ms 492 KB Output is correct
8 Correct 6 ms 492 KB Output is correct
9 Correct 6 ms 492 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 5 ms 492 KB Output is correct
12 Correct 5 ms 492 KB Output is correct
13 Correct 7 ms 492 KB Output is correct
14 Correct 6 ms 492 KB Output is correct
15 Correct 5 ms 492 KB Output is correct
16 Correct 4 ms 512 KB Output is correct
17 Correct 5 ms 636 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 6764 KB Output is correct
2 Correct 189 ms 6636 KB Output is correct
3 Correct 179 ms 6636 KB Output is correct
4 Correct 136 ms 6380 KB Output is correct
5 Correct 137 ms 6380 KB Output is correct
6 Correct 104 ms 5996 KB Output is correct
7 Correct 175 ms 6636 KB Output is correct
8 Correct 174 ms 6636 KB Output is correct
9 Correct 167 ms 6636 KB Output is correct
10 Correct 131 ms 6124 KB Output is correct
11 Correct 127 ms 6124 KB Output is correct
12 Correct 82 ms 5612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 6764 KB Output is correct
2 Correct 189 ms 6636 KB Output is correct
3 Correct 179 ms 6636 KB Output is correct
4 Correct 136 ms 6380 KB Output is correct
5 Correct 137 ms 6380 KB Output is correct
6 Correct 104 ms 5996 KB Output is correct
7 Correct 175 ms 6636 KB Output is correct
8 Correct 174 ms 6636 KB Output is correct
9 Correct 167 ms 6636 KB Output is correct
10 Correct 131 ms 6124 KB Output is correct
11 Correct 127 ms 6124 KB Output is correct
12 Correct 82 ms 5612 KB Output is correct
13 Correct 181 ms 6636 KB Output is correct
14 Correct 180 ms 6640 KB Output is correct
15 Correct 179 ms 6636 KB Output is correct
16 Correct 139 ms 6380 KB Output is correct
17 Correct 139 ms 6380 KB Output is correct
18 Correct 105 ms 5992 KB Output is correct
19 Correct 182 ms 6760 KB Output is correct
20 Correct 180 ms 6636 KB Output is correct
21 Correct 178 ms 6632 KB Output is correct
22 Correct 129 ms 6208 KB Output is correct
23 Correct 131 ms 6124 KB Output is correct
24 Correct 82 ms 5612 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 6 ms 492 KB Output is correct
8 Correct 6 ms 492 KB Output is correct
9 Correct 6 ms 492 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 5 ms 492 KB Output is correct
12 Correct 5 ms 492 KB Output is correct
13 Correct 7 ms 492 KB Output is correct
14 Correct 6 ms 492 KB Output is correct
15 Correct 5 ms 492 KB Output is correct
16 Correct 4 ms 512 KB Output is correct
17 Correct 5 ms 636 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
19 Correct 181 ms 6764 KB Output is correct
20 Correct 189 ms 6636 KB Output is correct
21 Correct 179 ms 6636 KB Output is correct
22 Correct 136 ms 6380 KB Output is correct
23 Correct 137 ms 6380 KB Output is correct
24 Correct 104 ms 5996 KB Output is correct
25 Correct 175 ms 6636 KB Output is correct
26 Correct 174 ms 6636 KB Output is correct
27 Correct 167 ms 6636 KB Output is correct
28 Correct 131 ms 6124 KB Output is correct
29 Correct 127 ms 6124 KB Output is correct
30 Correct 82 ms 5612 KB Output is correct
31 Correct 181 ms 6636 KB Output is correct
32 Correct 180 ms 6640 KB Output is correct
33 Correct 179 ms 6636 KB Output is correct
34 Correct 139 ms 6380 KB Output is correct
35 Correct 139 ms 6380 KB Output is correct
36 Correct 105 ms 5992 KB Output is correct
37 Correct 182 ms 6760 KB Output is correct
38 Correct 180 ms 6636 KB Output is correct
39 Correct 178 ms 6632 KB Output is correct
40 Correct 129 ms 6208 KB Output is correct
41 Correct 131 ms 6124 KB Output is correct
42 Correct 82 ms 5612 KB Output is correct
43 Correct 203 ms 7532 KB Output is correct
44 Correct 202 ms 7532 KB Output is correct
45 Correct 203 ms 7532 KB Output is correct
46 Correct 148 ms 6764 KB Output is correct
47 Correct 149 ms 6764 KB Output is correct
48 Correct 106 ms 5740 KB Output is correct
49 Correct 204 ms 7660 KB Output is correct
50 Correct 197 ms 7660 KB Output is correct
51 Correct 192 ms 7660 KB Output is correct
52 Correct 157 ms 6636 KB Output is correct
53 Correct 136 ms 6636 KB Output is correct