답안 #978084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978084 2024-05-08T18:49:09 Z happy_node Examination (JOI19_examination) C++17
100 / 100
815 ms 55788 KB
#include <bits/stdc++.h>
using namespace std;

const int MX=1e6+5;
int N,Q;
int S[MX],T[MX], X[MX], Y[MX], Z[MX], ans[MX];

struct fenwick {
	int t[MX];

	void upd(int pos, int val) {
		for(int i=pos;i<MX;i+=i&-i) t[i]+=val;
	}

	int que(int pos) {
		int res=0;
		for(int i=pos;i>0;i-=i&-i) res+=t[i];
		return res;
	}
} ft, tt;

map<int,int> id;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);

	cin>>N>>Q;

	for(int i=1;i<=N;i++) cin>>S[i]>>T[i];
	for(int i=1;i<=Q;i++) {
		cin>>X[i]>>Y[i]>>Z[i];
		Z[i]=max(Z[i],X[i]+Y[i]);
	}

	map<int,int> id;
	for(int i=1;i<=N;i++) {
		id[S[i]]=0;
		id[T[i]]=0;
		id[S[i]+T[i]]=0;
	}
	for(int i=1;i<=Q;i++) {
		id[X[i]]=0;
		id[Y[i]]=0;
		id[Z[i]]=0;
	}

	int z=1;
	for(auto &[x,y]:id) y=z++;

	vector<array<int,4>> v;
	for(int i=1;i<=N;i++) 
		v.push_back({S[i]+T[i],S[i],T[i],MX});
	for(int i=1;i<=Q;i++) 
		v.push_back({Z[i],X[i],Y[i],i});

	sort(v.rbegin(),v.rend());

	int cnt=0;
	for(auto [s,x,y,i]:v) {
		if(i==MX) {
			cnt+=1;
			ft.upd(id[x],1);
			tt.upd(id[y],1);
		} else {
			ans[i]=cnt-ft.que(id[x]-1)-tt.que(id[y]-1);
		}
	}

	for(int i=1;i<=Q;i++) {
		cout<<ans[i]<<'\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Correct 2 ms 16732 KB Output is correct
3 Correct 3 ms 19032 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 3 ms 16728 KB Output is correct
6 Correct 2 ms 16732 KB Output is correct
7 Correct 9 ms 18248 KB Output is correct
8 Correct 9 ms 18228 KB Output is correct
9 Correct 9 ms 18012 KB Output is correct
10 Correct 7 ms 17756 KB Output is correct
11 Correct 7 ms 17756 KB Output is correct
12 Correct 5 ms 19184 KB Output is correct
13 Correct 9 ms 18020 KB Output is correct
14 Correct 9 ms 20056 KB Output is correct
15 Correct 9 ms 20192 KB Output is correct
16 Correct 6 ms 17568 KB Output is correct
17 Correct 6 ms 17500 KB Output is correct
18 Correct 4 ms 16988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 315 ms 29460 KB Output is correct
2 Correct 282 ms 31672 KB Output is correct
3 Correct 264 ms 27316 KB Output is correct
4 Correct 149 ms 27312 KB Output is correct
5 Correct 150 ms 29476 KB Output is correct
6 Correct 73 ms 23744 KB Output is correct
7 Correct 272 ms 32440 KB Output is correct
8 Correct 254 ms 32176 KB Output is correct
9 Correct 231 ms 31532 KB Output is correct
10 Correct 142 ms 24760 KB Output is correct
11 Correct 147 ms 28632 KB Output is correct
12 Correct 61 ms 21524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 315 ms 29460 KB Output is correct
2 Correct 282 ms 31672 KB Output is correct
3 Correct 264 ms 27316 KB Output is correct
4 Correct 149 ms 27312 KB Output is correct
5 Correct 150 ms 29476 KB Output is correct
6 Correct 73 ms 23744 KB Output is correct
7 Correct 272 ms 32440 KB Output is correct
8 Correct 254 ms 32176 KB Output is correct
9 Correct 231 ms 31532 KB Output is correct
10 Correct 142 ms 24760 KB Output is correct
11 Correct 147 ms 28632 KB Output is correct
12 Correct 61 ms 21524 KB Output is correct
13 Correct 294 ms 28372 KB Output is correct
14 Correct 269 ms 31912 KB Output is correct
15 Correct 271 ms 28216 KB Output is correct
16 Correct 162 ms 27576 KB Output is correct
17 Correct 161 ms 25912 KB Output is correct
18 Correct 77 ms 23620 KB Output is correct
19 Correct 270 ms 28168 KB Output is correct
20 Correct 270 ms 31640 KB Output is correct
21 Correct 281 ms 30236 KB Output is correct
22 Correct 137 ms 25784 KB Output is correct
23 Correct 138 ms 27060 KB Output is correct
24 Correct 63 ms 22068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Correct 2 ms 16732 KB Output is correct
3 Correct 3 ms 19032 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 3 ms 16728 KB Output is correct
6 Correct 2 ms 16732 KB Output is correct
7 Correct 9 ms 18248 KB Output is correct
8 Correct 9 ms 18228 KB Output is correct
9 Correct 9 ms 18012 KB Output is correct
10 Correct 7 ms 17756 KB Output is correct
11 Correct 7 ms 17756 KB Output is correct
12 Correct 5 ms 19184 KB Output is correct
13 Correct 9 ms 18020 KB Output is correct
14 Correct 9 ms 20056 KB Output is correct
15 Correct 9 ms 20192 KB Output is correct
16 Correct 6 ms 17568 KB Output is correct
17 Correct 6 ms 17500 KB Output is correct
18 Correct 4 ms 16988 KB Output is correct
19 Correct 315 ms 29460 KB Output is correct
20 Correct 282 ms 31672 KB Output is correct
21 Correct 264 ms 27316 KB Output is correct
22 Correct 149 ms 27312 KB Output is correct
23 Correct 150 ms 29476 KB Output is correct
24 Correct 73 ms 23744 KB Output is correct
25 Correct 272 ms 32440 KB Output is correct
26 Correct 254 ms 32176 KB Output is correct
27 Correct 231 ms 31532 KB Output is correct
28 Correct 142 ms 24760 KB Output is correct
29 Correct 147 ms 28632 KB Output is correct
30 Correct 61 ms 21524 KB Output is correct
31 Correct 294 ms 28372 KB Output is correct
32 Correct 269 ms 31912 KB Output is correct
33 Correct 271 ms 28216 KB Output is correct
34 Correct 162 ms 27576 KB Output is correct
35 Correct 161 ms 25912 KB Output is correct
36 Correct 77 ms 23620 KB Output is correct
37 Correct 270 ms 28168 KB Output is correct
38 Correct 270 ms 31640 KB Output is correct
39 Correct 281 ms 30236 KB Output is correct
40 Correct 137 ms 25784 KB Output is correct
41 Correct 138 ms 27060 KB Output is correct
42 Correct 63 ms 22068 KB Output is correct
43 Correct 712 ms 53316 KB Output is correct
44 Correct 683 ms 53180 KB Output is correct
45 Correct 666 ms 54200 KB Output is correct
46 Correct 318 ms 42516 KB Output is correct
47 Correct 307 ms 44476 KB Output is correct
48 Correct 75 ms 21432 KB Output is correct
49 Correct 815 ms 55788 KB Output is correct
50 Correct 730 ms 53284 KB Output is correct
51 Correct 744 ms 55740 KB Output is correct
52 Correct 234 ms 38072 KB Output is correct
53 Correct 200 ms 34988 KB Output is correct