답안 #699056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699056 2023-02-15T13:17:22 Z Sandarach151 Examination (JOI19_examination) C++17
100 / 100
265 ms 15472 KB
#include <bits/stdc++.h>
using namespace std;
 
class segmenttree{
	private:
		vector<int> vect;
		int sze;		
		void privupdate(int segpos, int segleft, int segright, int arrpos, int val){
			if(segleft!=segright){
				int segmid = (segleft+segright)/2;
				if(arrpos<=segmid){
					privupdate(2*segpos+1, segleft, segmid, arrpos, val);
				}
				else{
					privupdate(2*segpos+2, segmid+1, segright, arrpos, val);
				}
				vect[segpos]=vect[2*segpos+1]+vect[2*segpos+2];
			}
			else{
				vect[segpos]+=val;
			}
		}
		int privquery(int segpos, int segleft, int segright, int arrleft, int arrright){
			if(arrleft==segleft && arrright==segright){
				return vect[segpos];
			}
			else{
				int segmid = (segleft+segright)/2;
				if(arrright<=segmid){
					return privquery(2*segpos+1, segleft, segmid, arrleft, arrright);
				}
				else if(arrleft>segmid){
					return privquery(2*segpos+2, segmid+1, segright, arrleft, arrright);
				}
				else{
					return privquery(2*segpos+1, segleft, segmid, arrleft, segmid)+privquery(2*segpos+2, segmid+1, segright, segmid+1, arrright);
				}
			}
		}
	public:
		segmenttree(int _sze):sze(_sze){
			vect.resize(4*sze+5, 0);
		}
		int query(int left, int right){
			return privquery(0, 0, sze-1, left, right);
		}
		void update(int pos, int val){
			privupdate(0, 0, sze-1, pos, val);
		}
};
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, q;
	cin >> n >> q;
	pair<int, pair<int, int> > arr[n];
	segmenttree one(n+1);
	segmenttree two(n+1);
	vector<pair<int, int> > arr11(n);
	vector<pair<int, int> > arr12(n);
	vector<pair<int, int> > arr21(n);
	vector<pair<int, int> > arr22(n);
	for(int i=0; i<n; i++){
		cin >> arr[i].second.first >> arr[i].second.second;
		arr[i].first = arr[i].second.first+arr[i].second.second;
		one.update(i, 1);
		two.update(i, 1);
	}
	sort(arr, arr+n);
	for(int i=0; i<n; i++){
		arr11[i].first = arr[i].second.first;
		arr21[i].first = arr[i].second.second;
		
		arr12[i].first = arr[i].second.first;
		arr12[i].second = i;
		arr22[i].first = arr[i].second.second;
		arr22[i].second = i;
	}
	sort(arr12.begin(), arr12.end());
	sort(arr22.begin(), arr22.end());
	for(int i=0; i<n; i++){
		arr11[arr12[i].second].second=i;
		arr21[arr22[i].second].second=i;
	}
	pair<tuple<int, int, int, int>, int> queries[q]; // sum, first, second, pos, ans;
	for(int i=0; i<q; i++){
		int a, b, c;
		cin >> a >> b >> c;
		queries[i].first = {max(c, a+b), a, b, i};
	}
	sort(queries, queries+q);
	int posq = 0;
	for(int i=0; i<n; i++){
		while(posq<q && get<0>(queries[posq].first)<=arr[i].first){
			int aa = get<1>(queries[posq].first);
			int bb = get<2>(queries[posq].first);
			pair<int, int> temp1 = {aa, 0};
			pair<int, int> temp2 = {bb, 0};
			int a = lower_bound(arr12.begin(), arr12.end(), temp1)-arr12.begin();
			int b = lower_bound(arr22.begin(), arr22.end(), temp2)-arr22.begin();
			int c = one.query(a, n);
			int d = two.query(b, n);
			int e = n-i;
			queries[posq].second = c+d-e;
			posq++;
		}
		one.update(arr11[i].second, -1);
		two.update(arr21[i].second, -1);
	}
	int ans[q];
	for(int i=0; i<q; i++){
		ans[get<3>(queries[i].first)]=queries[i].second;
	}
	for(int i=0; i<q; i++){
		cout << ans[i] << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 7 ms 724 KB Output is correct
8 Correct 8 ms 652 KB Output is correct
9 Correct 5 ms 724 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 716 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 5 ms 720 KB Output is correct
15 Correct 5 ms 664 KB Output is correct
16 Correct 4 ms 608 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 4 ms 552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 10704 KB Output is correct
2 Correct 177 ms 10612 KB Output is correct
3 Correct 189 ms 13108 KB Output is correct
4 Correct 131 ms 12352 KB Output is correct
5 Correct 138 ms 12368 KB Output is correct
6 Correct 123 ms 11592 KB Output is correct
7 Correct 162 ms 12992 KB Output is correct
8 Correct 176 ms 13024 KB Output is correct
9 Correct 170 ms 12916 KB Output is correct
10 Correct 119 ms 12236 KB Output is correct
11 Correct 130 ms 12228 KB Output is correct
12 Correct 87 ms 11212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 10704 KB Output is correct
2 Correct 177 ms 10612 KB Output is correct
3 Correct 189 ms 13108 KB Output is correct
4 Correct 131 ms 12352 KB Output is correct
5 Correct 138 ms 12368 KB Output is correct
6 Correct 123 ms 11592 KB Output is correct
7 Correct 162 ms 12992 KB Output is correct
8 Correct 176 ms 13024 KB Output is correct
9 Correct 170 ms 12916 KB Output is correct
10 Correct 119 ms 12236 KB Output is correct
11 Correct 130 ms 12228 KB Output is correct
12 Correct 87 ms 11212 KB Output is correct
13 Correct 223 ms 13576 KB Output is correct
14 Correct 199 ms 13492 KB Output is correct
15 Correct 181 ms 13104 KB Output is correct
16 Correct 188 ms 12752 KB Output is correct
17 Correct 152 ms 12748 KB Output is correct
18 Correct 122 ms 11636 KB Output is correct
19 Correct 260 ms 13540 KB Output is correct
20 Correct 220 ms 13524 KB Output is correct
21 Correct 200 ms 13520 KB Output is correct
22 Correct 134 ms 12228 KB Output is correct
23 Correct 116 ms 12232 KB Output is correct
24 Correct 93 ms 11212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 7 ms 724 KB Output is correct
8 Correct 8 ms 652 KB Output is correct
9 Correct 5 ms 724 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 716 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 5 ms 720 KB Output is correct
15 Correct 5 ms 664 KB Output is correct
16 Correct 4 ms 608 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 4 ms 552 KB Output is correct
19 Correct 191 ms 10704 KB Output is correct
20 Correct 177 ms 10612 KB Output is correct
21 Correct 189 ms 13108 KB Output is correct
22 Correct 131 ms 12352 KB Output is correct
23 Correct 138 ms 12368 KB Output is correct
24 Correct 123 ms 11592 KB Output is correct
25 Correct 162 ms 12992 KB Output is correct
26 Correct 176 ms 13024 KB Output is correct
27 Correct 170 ms 12916 KB Output is correct
28 Correct 119 ms 12236 KB Output is correct
29 Correct 130 ms 12228 KB Output is correct
30 Correct 87 ms 11212 KB Output is correct
31 Correct 223 ms 13576 KB Output is correct
32 Correct 199 ms 13492 KB Output is correct
33 Correct 181 ms 13104 KB Output is correct
34 Correct 188 ms 12752 KB Output is correct
35 Correct 152 ms 12748 KB Output is correct
36 Correct 122 ms 11636 KB Output is correct
37 Correct 260 ms 13540 KB Output is correct
38 Correct 220 ms 13524 KB Output is correct
39 Correct 200 ms 13520 KB Output is correct
40 Correct 134 ms 12228 KB Output is correct
41 Correct 116 ms 12232 KB Output is correct
42 Correct 93 ms 11212 KB Output is correct
43 Correct 201 ms 15472 KB Output is correct
44 Correct 205 ms 15424 KB Output is correct
45 Correct 265 ms 15464 KB Output is correct
46 Correct 151 ms 13928 KB Output is correct
47 Correct 156 ms 13928 KB Output is correct
48 Correct 110 ms 11452 KB Output is correct
49 Correct 177 ms 15432 KB Output is correct
50 Correct 187 ms 15412 KB Output is correct
51 Correct 174 ms 15328 KB Output is correct
52 Correct 129 ms 13776 KB Output is correct
53 Correct 114 ms 13000 KB Output is correct