Submission #105562

# Submission time Handle Problem Language Result Execution time Memory
105562 2019-04-13T13:42:59 Z Pro_ktmr Examination (JOI19_examination) C++14
100 / 100
1489 ms 82472 KB
#include"bits/stdc++.h"
using namespace std;
#define MP make_pair
#define PB push_back

int N,Q;
vector<pair<int,int>> score;//math,info
vector<pair<int,int>> score2;//info,moto
vector<pair<pair<int,int>,pair<int,int>>> query;//info,math,sum,moto
int ans[100000];

struct RSQ{
public:
	int N;
	vector<int> sorted;
	vector<bool> already;
	vector<int> node;
	
	void init(int n){
		N = n;
		for(int i=0; i<2*N-1; i++) node.PB(0);
	}
	void add(int x){
		int k = lower_bound(sorted.begin(), sorted.end(), x) - sorted.begin();
		k += N-1;
		node[k]++;
		while(k > 0){
			k = (k-1)/2;
			node[k]++;
		}
	}
	int sum(int x){
		x = lower_bound(sorted.begin(), sorted.end(), x) - sorted.begin();
		return query(x, N, 0, 0, N);
	}
	int query(int a, int b, int k, int l, int r){
		if(r <= a || b <= l) return 0;
		if(a <= l && r <= b){
			return node[k];
		}
		return query(a, b, 2*k+1, l, (l+r)/2) + query(a, b, 2*k+2, (l+r)/2, r);
	}
};

struct SegmentTree{
public:
	int N;
	RSQ node[100000*4];
	void init(int n){
		N = 1;
		while(N < n) N *= 2;
		rsq(0, 0, N, n);
	}
	void rsq(int k, int l, int r, int n){
		node[k].init(r-l);
		for(int i=l; i<min(r,n); i++){
			node[k].sorted.PB(score[i].first+score[i].second);
		}
		/*for(int i=min(r,n); i<r; i++){
			node[k].sorted.PB(-1);
			already
		}*/
		sort(node[k].sorted.begin(), node[k].sorted.end());
		if(r-l != 1){
			rsq(2*k+1, l, (l+r)/2, n);
			rsq(2*k+2, (l+r)/2, r, n);
		}
	}
	void add(int k){
		int i = k;
		k += N-1;
		node[k].add(score[i].first+score[i].second);
		while(k > 0){
			k = (k-1)/2;
			node[k].add(score[i].first+score[i].second);
		}
	}
	int culc(int a, int b, int x, int k=0, int l=0, int r=-1){
		if(r == -1) r = N;
		if(r <= a || b <= l) return 0;
		if(a <= l && r <= b){
			return node[k].sum(x);
		}
		else{
			return culc(a, b, x, 2*k+1, l, (l+r)/2) + culc(a, b, x, 2*k+2, (l+r)/2, r);
		}
	}
};

SegmentTree st;
signed main(){
	scanf("%d%d", &N, &Q);
	score.resize(N);
	for(int i=0; i<N; i++){
		scanf("%d%d", &score[i].first, &score[i].second);
	}
	sort(score.begin(), score.end());
	query.resize(Q);
	for(int i=0; i<Q; i++){
		scanf("%d%d%d", &query[i].first.second, &query[i].first.first, &query[i].second.first);
		query[i].second.second = i;
	}
	sort(query.begin(), query.end());
	
	for(int i=0; i<N; i++) score2.PB(MP(score[i].second, i));
	sort(score2.begin(), score2.end());
	
	//
	
	st.init(N);
	
	int now = N-1;
	for(int i=Q-1; i>=0; i--){
		while(now >=0 && score2[now].first >= query[i].first.first){
			st.add(score2[now].second);
			now--;
		}
		int a = lower_bound(score.begin(), score.end(), MP(query[i].first.second, 0)) - score.begin();
		ans[query[i].second.second] = st.culc(a, N, query[i].second.first);
	}
	
	for(int i=0; i<Q; i++){
		printf("%d\n", ans[i]);
	}
	
	return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:92:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &Q);
  ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:95:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &score[i].first, &score[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:100:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &query[i].first.second, &query[i].first.first, &query[i].second.first);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 37880 KB Output is correct
2 Correct 41 ms 37880 KB Output is correct
3 Correct 47 ms 37880 KB Output is correct
4 Correct 47 ms 38008 KB Output is correct
5 Correct 42 ms 38084 KB Output is correct
6 Correct 36 ms 37880 KB Output is correct
7 Correct 53 ms 39032 KB Output is correct
8 Correct 56 ms 39032 KB Output is correct
9 Correct 53 ms 39032 KB Output is correct
10 Correct 53 ms 39032 KB Output is correct
11 Correct 47 ms 38952 KB Output is correct
12 Correct 45 ms 38904 KB Output is correct
13 Correct 54 ms 39032 KB Output is correct
14 Correct 49 ms 39032 KB Output is correct
15 Correct 55 ms 39032 KB Output is correct
16 Correct 47 ms 38904 KB Output is correct
17 Correct 50 ms 39032 KB Output is correct
18 Correct 44 ms 38912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1107 ms 80108 KB Output is correct
2 Correct 1196 ms 79980 KB Output is correct
3 Correct 1136 ms 80020 KB Output is correct
4 Correct 744 ms 79244 KB Output is correct
5 Correct 611 ms 79160 KB Output is correct
6 Correct 436 ms 78444 KB Output is correct
7 Correct 1028 ms 80108 KB Output is correct
8 Correct 1150 ms 79976 KB Output is correct
9 Correct 1026 ms 79840 KB Output is correct
10 Correct 439 ms 79084 KB Output is correct
11 Correct 511 ms 79084 KB Output is correct
12 Correct 324 ms 78060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1107 ms 80108 KB Output is correct
2 Correct 1196 ms 79980 KB Output is correct
3 Correct 1136 ms 80020 KB Output is correct
4 Correct 744 ms 79244 KB Output is correct
5 Correct 611 ms 79160 KB Output is correct
6 Correct 436 ms 78444 KB Output is correct
7 Correct 1028 ms 80108 KB Output is correct
8 Correct 1150 ms 79976 KB Output is correct
9 Correct 1026 ms 79840 KB Output is correct
10 Correct 439 ms 79084 KB Output is correct
11 Correct 511 ms 79084 KB Output is correct
12 Correct 324 ms 78060 KB Output is correct
13 Correct 1368 ms 80564 KB Output is correct
14 Correct 1290 ms 80216 KB Output is correct
15 Correct 1137 ms 79912 KB Output is correct
16 Correct 776 ms 79548 KB Output is correct
17 Correct 729 ms 79568 KB Output is correct
18 Correct 419 ms 78524 KB Output is correct
19 Correct 1457 ms 80484 KB Output is correct
20 Correct 1357 ms 80480 KB Output is correct
21 Correct 1281 ms 80328 KB Output is correct
22 Correct 432 ms 79036 KB Output is correct
23 Correct 575 ms 79020 KB Output is correct
24 Correct 415 ms 78008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 37880 KB Output is correct
2 Correct 41 ms 37880 KB Output is correct
3 Correct 47 ms 37880 KB Output is correct
4 Correct 47 ms 38008 KB Output is correct
5 Correct 42 ms 38084 KB Output is correct
6 Correct 36 ms 37880 KB Output is correct
7 Correct 53 ms 39032 KB Output is correct
8 Correct 56 ms 39032 KB Output is correct
9 Correct 53 ms 39032 KB Output is correct
10 Correct 53 ms 39032 KB Output is correct
11 Correct 47 ms 38952 KB Output is correct
12 Correct 45 ms 38904 KB Output is correct
13 Correct 54 ms 39032 KB Output is correct
14 Correct 49 ms 39032 KB Output is correct
15 Correct 55 ms 39032 KB Output is correct
16 Correct 47 ms 38904 KB Output is correct
17 Correct 50 ms 39032 KB Output is correct
18 Correct 44 ms 38912 KB Output is correct
19 Correct 1107 ms 80108 KB Output is correct
20 Correct 1196 ms 79980 KB Output is correct
21 Correct 1136 ms 80020 KB Output is correct
22 Correct 744 ms 79244 KB Output is correct
23 Correct 611 ms 79160 KB Output is correct
24 Correct 436 ms 78444 KB Output is correct
25 Correct 1028 ms 80108 KB Output is correct
26 Correct 1150 ms 79976 KB Output is correct
27 Correct 1026 ms 79840 KB Output is correct
28 Correct 439 ms 79084 KB Output is correct
29 Correct 511 ms 79084 KB Output is correct
30 Correct 324 ms 78060 KB Output is correct
31 Correct 1368 ms 80564 KB Output is correct
32 Correct 1290 ms 80216 KB Output is correct
33 Correct 1137 ms 79912 KB Output is correct
34 Correct 776 ms 79548 KB Output is correct
35 Correct 729 ms 79568 KB Output is correct
36 Correct 419 ms 78524 KB Output is correct
37 Correct 1457 ms 80484 KB Output is correct
38 Correct 1357 ms 80480 KB Output is correct
39 Correct 1281 ms 80328 KB Output is correct
40 Correct 432 ms 79036 KB Output is correct
41 Correct 575 ms 79020 KB Output is correct
42 Correct 415 ms 78008 KB Output is correct
43 Correct 1480 ms 82304 KB Output is correct
44 Correct 1489 ms 82288 KB Output is correct
45 Correct 1286 ms 82244 KB Output is correct
46 Correct 714 ms 80876 KB Output is correct
47 Correct 729 ms 80876 KB Output is correct
48 Correct 418 ms 78316 KB Output is correct
49 Correct 1337 ms 82220 KB Output is correct
50 Correct 1267 ms 82472 KB Output is correct
51 Correct 1177 ms 82284 KB Output is correct
52 Correct 511 ms 80492 KB Output is correct
53 Correct 485 ms 79736 KB Output is correct