답안 #383969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
383969 2021-03-31T05:56:16 Z ritul_kr_singh Examination (JOI19_examination) C++17
100 / 100
243 ms 14672 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' << 
#define nl << '\n'

struct FenwickTree{
	vector<int> a; int n, s;
	FenwickTree(int _n){ a.resize((n=_n)+1); }
	void add(int i){
		for(++i; i<=n; i+=i&-i) ++a[i];
	}
	int get(int i){
		for(s=0; i>=1; i-=i&-i) s += a[i];
		return s;
	}
	int get(int l, int r){ return get(r+1) - get(l); }
};

int C(int val, vector<int> &vals){
	return lower_bound(vals.begin(), vals.end(), val) - vals.begin();
}

signed main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, q; cin >> n >> q;
	array<int, 4> a[n+q];
	vector<int> vals1, vals2;
	for(int i=0; i<n; ++i){
		cin >> a[i][1] >> a[i][2];
		vals1.push_back(a[i][1]);
		vals2.push_back(a[i][2]);
		a[i][0] = a[i][1] + a[i][2];
	}
	for(int i=n; i<n+q; ++i){
		cin >> a[i][1] >> a[i][2] >> a[i][0];
		vals1.push_back(a[i][1]);
		vals2.push_back(a[i][2]);
		a[i][0] = max(a[i][0], a[i][1] + a[i][2]);
		a[i][1] -= 1e10;
		a[i][3] = i-n;
	}
	sort(a, a+n+q, greater<>());
	sort(vals1.begin(), vals1.end());
	sort(vals2.begin(), vals2.end());
	vals1.resize(unique(vals1.begin(), vals1.end()) - vals1.begin());
	vals2.resize(unique(vals2.begin(), vals2.end()) - vals2.begin());

	FenwickTree b1(vals1.size()), b2(vals2.size());
	int ans[q], total = 0;

	for(auto &i : a){
		if(i[1]<0){
			i[1] += 1e10;
			ans[i[3]] = total - b1.get(0, C(i[1], vals1)-1) - b2.get(0, C(i[2], vals2)-1);
		}else{
			b1.add(C(i[1], vals1));
			b2.add(C(i[2], vals2));
			++total;
		}
	}
	for(int i : ans) cout << i nl;
}
# 결과 실행 시간 메모리 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 748 KB Output is correct
8 Correct 6 ms 748 KB Output is correct
9 Correct 6 ms 748 KB Output is correct
10 Correct 5 ms 748 KB Output is correct
11 Correct 5 ms 748 KB Output is correct
12 Correct 4 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 6 ms 748 KB Output is correct
15 Correct 7 ms 876 KB Output is correct
16 Correct 4 ms 748 KB Output is correct
17 Correct 5 ms 896 KB Output is correct
18 Correct 4 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 12496 KB Output is correct
2 Correct 194 ms 12496 KB Output is correct
3 Correct 191 ms 12496 KB Output is correct
4 Correct 127 ms 11728 KB Output is correct
5 Correct 126 ms 11728 KB Output is correct
6 Correct 99 ms 11344 KB Output is correct
7 Correct 180 ms 12368 KB Output is correct
8 Correct 184 ms 12368 KB Output is correct
9 Correct 171 ms 12240 KB Output is correct
10 Correct 118 ms 11728 KB Output is correct
11 Correct 118 ms 11728 KB Output is correct
12 Correct 91 ms 10960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 12496 KB Output is correct
2 Correct 194 ms 12496 KB Output is correct
3 Correct 191 ms 12496 KB Output is correct
4 Correct 127 ms 11728 KB Output is correct
5 Correct 126 ms 11728 KB Output is correct
6 Correct 99 ms 11344 KB Output is correct
7 Correct 180 ms 12368 KB Output is correct
8 Correct 184 ms 12368 KB Output is correct
9 Correct 171 ms 12240 KB Output is correct
10 Correct 118 ms 11728 KB Output is correct
11 Correct 118 ms 11728 KB Output is correct
12 Correct 91 ms 10960 KB Output is correct
13 Correct 194 ms 12512 KB Output is correct
14 Correct 191 ms 12504 KB Output is correct
15 Correct 189 ms 12496 KB Output is correct
16 Correct 134 ms 11728 KB Output is correct
17 Correct 133 ms 11856 KB Output is correct
18 Correct 104 ms 11344 KB Output is correct
19 Correct 193 ms 12624 KB Output is correct
20 Correct 198 ms 12496 KB Output is correct
21 Correct 189 ms 12368 KB Output is correct
22 Correct 133 ms 11728 KB Output is correct
23 Correct 125 ms 11728 KB Output is correct
24 Correct 92 ms 10960 KB Output is correct
# 결과 실행 시간 메모리 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 748 KB Output is correct
8 Correct 6 ms 748 KB Output is correct
9 Correct 6 ms 748 KB Output is correct
10 Correct 5 ms 748 KB Output is correct
11 Correct 5 ms 748 KB Output is correct
12 Correct 4 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 6 ms 748 KB Output is correct
15 Correct 7 ms 876 KB Output is correct
16 Correct 4 ms 748 KB Output is correct
17 Correct 5 ms 896 KB Output is correct
18 Correct 4 ms 748 KB Output is correct
19 Correct 219 ms 12496 KB Output is correct
20 Correct 194 ms 12496 KB Output is correct
21 Correct 191 ms 12496 KB Output is correct
22 Correct 127 ms 11728 KB Output is correct
23 Correct 126 ms 11728 KB Output is correct
24 Correct 99 ms 11344 KB Output is correct
25 Correct 180 ms 12368 KB Output is correct
26 Correct 184 ms 12368 KB Output is correct
27 Correct 171 ms 12240 KB Output is correct
28 Correct 118 ms 11728 KB Output is correct
29 Correct 118 ms 11728 KB Output is correct
30 Correct 91 ms 10960 KB Output is correct
31 Correct 194 ms 12512 KB Output is correct
32 Correct 191 ms 12504 KB Output is correct
33 Correct 189 ms 12496 KB Output is correct
34 Correct 134 ms 11728 KB Output is correct
35 Correct 133 ms 11856 KB Output is correct
36 Correct 104 ms 11344 KB Output is correct
37 Correct 193 ms 12624 KB Output is correct
38 Correct 198 ms 12496 KB Output is correct
39 Correct 189 ms 12368 KB Output is correct
40 Correct 133 ms 11728 KB Output is correct
41 Correct 125 ms 11728 KB Output is correct
42 Correct 92 ms 10960 KB Output is correct
43 Correct 243 ms 14672 KB Output is correct
44 Correct 232 ms 14544 KB Output is correct
45 Correct 226 ms 14560 KB Output is correct
46 Correct 140 ms 12840 KB Output is correct
47 Correct 141 ms 12880 KB Output is correct
48 Correct 101 ms 11088 KB Output is correct
49 Correct 212 ms 14544 KB Output is correct
50 Correct 228 ms 14416 KB Output is correct
51 Correct 214 ms 14544 KB Output is correct
52 Correct 136 ms 12752 KB Output is correct
53 Correct 123 ms 12752 KB Output is correct