Submission #197881

# Submission time Handle Problem Language Result Execution time Memory
197881 2020-01-24T02:43:22 Z gs18081 Examination (JOI19_examination) C++17
100 / 100
675 ms 50732 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;

const int MAXN = 101010;

struct PST{
	struct Node{
		int v,l,r;
	}tree[MAXN * 40];
	int n;
	int t;
	PST(){}
	void resize(int size){
		n = size;
		t = 1;
		tree[0].v = tree[0].l = tree[0].r = 0;
	}
	void upnode(int node){
		tree[node].v = tree[tree[node].l].v + tree[tree[node].r].v;
	}
	int update(int prevnode,int s,int e,int pos,int diff){
		if(e < pos || pos < s) return prevnode;
		if(s == e){
			int now = t++;
			tree[now].v = tree[prevnode].v + diff;
			return now;
		}
		int now = t++;
		int m = (s + e) >> 1;
		tree[now].l = update(tree[prevnode].l,s,m,pos,diff);
		tree[now].r = update(tree[prevnode].r,m + 1,e,pos,diff);
		upnode(now);
		return now;
	}
	int update(int prevroot,int pos,int diff){
		return update(prevroot,0,n-1,pos,diff);
	}
	int range(int node,int s,int e,int l,int r){
		if(e < l||r < s) return 0;
		if(l <= s && e <= r) return tree[node].v;
		int m = (s + e) >> 1;
		return range(tree[node].l,s,m,l,r) + range(tree[node].r,m+1,e,l,r);
	}
	int range(int root,int srt){
		return range(root,0,n-1,srt,n-1);
	}
};

int N,Q;
vector<int> addv;
vector<int> bv;
vector<int> addroot;
vector<int> broot;
vector<ti> vect;
PST addpst;
PST bpst;


int main(){
	scanf("%d %d",&N,&Q);
	vect.push_back(ti(-1,-1,-1));
	addroot.push_back(0);
	broot.push_back(0);
	for(int i=1;i<=N;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		vect.push_back(ti(a,b,a+b));
		addv.push_back(a+b);
		bv.push_back(b);
	}
	sort(addv.begin(),addv.end());
	addv.resize(unique(addv.begin(),addv.end()) - addv.begin());
	sort(bv.begin(),bv.end());
	bv.resize(unique(bv.begin(),bv.end()) - bv.begin());
	sort(vect.begin() + 1,vect.end());
	addpst.resize(addv.size());
	bpst.resize(bv.size());
	for(int i=1;i<=N;i++){
		auto [a,b,c] = vect[i];
		b = lower_bound(bv.begin(),bv.end(),b) - bv.begin();
		c = lower_bound(addv.begin(),addv.end(),c) - addv.begin();
		vect[i] = ti(a,b,c);
		addroot.push_back(addpst.update(addroot.back() , c , 1));
		broot.push_back(bpst.update(broot.back() , b , 1));
	}
	for(int i=0;i<Q;i++){
		int a,b,c;
		int ans = 0;
		scanf("%d %d %d",&a,&b,&c);
		int srt = lower_bound(vect.begin(),vect.end(),ti(a,-1,-1)) - vect.begin();
		if(a + b < c){
			int tp = lower_bound(vect.begin(),vect.end(),ti(c - b,-1,-1)) - vect.begin() - 1;
			int addsrt = lower_bound(addv.begin(),addv.end(),c) - addv.begin();
			ans += addpst.range(addroot[tp],addsrt);
			ans -= addpst.range(addroot[srt - 1],addsrt);
			srt = tp + 1;
		}
	//	printf("ang %d\n",ans);
		int bsrt = lower_bound(bv.begin(),bv.end(),b) - bv.begin();
		ans += bpst.range(broot.back(),bsrt);
		ans -= bpst.range(broot[srt - 1],bsrt);
		printf("%d\n",ans);
	}


	return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:64: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:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a,&b);
   ~~~~~^~~~~~~~~~~~~~~
examination.cpp:93:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&a,&b,&c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 11 ms 1528 KB Output is correct
8 Correct 11 ms 1528 KB Output is correct
9 Correct 11 ms 1528 KB Output is correct
10 Correct 8 ms 1144 KB Output is correct
11 Correct 9 ms 1528 KB Output is correct
12 Correct 5 ms 888 KB Output is correct
13 Correct 10 ms 1628 KB Output is correct
14 Correct 10 ms 1528 KB Output is correct
15 Correct 10 ms 1528 KB Output is correct
16 Correct 8 ms 1388 KB Output is correct
17 Correct 7 ms 1016 KB Output is correct
18 Correct 4 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 461 ms 46760 KB Output is correct
2 Correct 465 ms 46832 KB Output is correct
3 Correct 464 ms 46808 KB Output is correct
4 Correct 209 ms 31244 KB Output is correct
5 Correct 327 ms 45912 KB Output is correct
6 Correct 106 ms 16940 KB Output is correct
7 Correct 370 ms 46732 KB Output is correct
8 Correct 402 ms 46888 KB Output is correct
9 Correct 349 ms 46720 KB Output is correct
10 Correct 239 ms 45580 KB Output is correct
11 Correct 152 ms 26796 KB Output is correct
12 Correct 69 ms 7212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 461 ms 46760 KB Output is correct
2 Correct 465 ms 46832 KB Output is correct
3 Correct 464 ms 46808 KB Output is correct
4 Correct 209 ms 31244 KB Output is correct
5 Correct 327 ms 45912 KB Output is correct
6 Correct 106 ms 16940 KB Output is correct
7 Correct 370 ms 46732 KB Output is correct
8 Correct 402 ms 46888 KB Output is correct
9 Correct 349 ms 46720 KB Output is correct
10 Correct 239 ms 45580 KB Output is correct
11 Correct 152 ms 26796 KB Output is correct
12 Correct 69 ms 7212 KB Output is correct
13 Correct 548 ms 47380 KB Output is correct
14 Correct 531 ms 47208 KB Output is correct
15 Correct 471 ms 46932 KB Output is correct
16 Correct 264 ms 31656 KB Output is correct
17 Correct 388 ms 46376 KB Output is correct
18 Correct 111 ms 16936 KB Output is correct
19 Correct 555 ms 47148 KB Output is correct
20 Correct 555 ms 47192 KB Output is correct
21 Correct 593 ms 47220 KB Output is correct
22 Correct 243 ms 45736 KB Output is correct
23 Correct 151 ms 26796 KB Output is correct
24 Correct 69 ms 7208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 11 ms 1528 KB Output is correct
8 Correct 11 ms 1528 KB Output is correct
9 Correct 11 ms 1528 KB Output is correct
10 Correct 8 ms 1144 KB Output is correct
11 Correct 9 ms 1528 KB Output is correct
12 Correct 5 ms 888 KB Output is correct
13 Correct 10 ms 1628 KB Output is correct
14 Correct 10 ms 1528 KB Output is correct
15 Correct 10 ms 1528 KB Output is correct
16 Correct 8 ms 1388 KB Output is correct
17 Correct 7 ms 1016 KB Output is correct
18 Correct 4 ms 508 KB Output is correct
19 Correct 461 ms 46760 KB Output is correct
20 Correct 465 ms 46832 KB Output is correct
21 Correct 464 ms 46808 KB Output is correct
22 Correct 209 ms 31244 KB Output is correct
23 Correct 327 ms 45912 KB Output is correct
24 Correct 106 ms 16940 KB Output is correct
25 Correct 370 ms 46732 KB Output is correct
26 Correct 402 ms 46888 KB Output is correct
27 Correct 349 ms 46720 KB Output is correct
28 Correct 239 ms 45580 KB Output is correct
29 Correct 152 ms 26796 KB Output is correct
30 Correct 69 ms 7212 KB Output is correct
31 Correct 548 ms 47380 KB Output is correct
32 Correct 531 ms 47208 KB Output is correct
33 Correct 471 ms 46932 KB Output is correct
34 Correct 264 ms 31656 KB Output is correct
35 Correct 388 ms 46376 KB Output is correct
36 Correct 111 ms 16936 KB Output is correct
37 Correct 555 ms 47148 KB Output is correct
38 Correct 555 ms 47192 KB Output is correct
39 Correct 593 ms 47220 KB Output is correct
40 Correct 243 ms 45736 KB Output is correct
41 Correct 151 ms 26796 KB Output is correct
42 Correct 69 ms 7208 KB Output is correct
43 Correct 594 ms 50660 KB Output is correct
44 Correct 596 ms 50600 KB Output is correct
45 Correct 572 ms 50732 KB Output is correct
46 Correct 284 ms 33704 KB Output is correct
47 Correct 421 ms 49224 KB Output is correct
48 Correct 113 ms 16776 KB Output is correct
49 Correct 613 ms 50600 KB Output is correct
50 Correct 583 ms 50732 KB Output is correct
51 Correct 675 ms 50488 KB Output is correct
52 Correct 328 ms 48812 KB Output is correct
53 Correct 163 ms 28584 KB Output is correct