Submission #771630

# Submission time Handle Problem Language Result Execution time Memory
771630 2023-07-03T07:33:13 Z Mohammad_Parsa Examination (JOI19_examination) C++17
100 / 100
506 ms 53732 KB
/* in the name of allah */
#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define F first
#define S second
#define mk make_pair
#define ln (e-s+1)
#define md ((s+e)/2)
#define lc (2*id)
#define rc (2*id+1)
typedef long long ll;

const int N=1e5+7;
int n,q,a,b,c,mn[4*N],mx[4*N],ans;
pair<int,int>x[N];
vector<int>v[2][4*N];

void merge(int id,int f){
	int i=0,j=0;
	int sz1=v[f][lc].size(),sz2=v[f][rc].size();
	while(i!=sz1 || j!=sz2){
		if(i==sz1){
			v[f][id].pb(v[f][rc][j++]);
		}
		else if(j==sz2){
			v[f][id].pb(v[f][lc][i++]);
		}
		else{
			if(v[f][lc][i]>v[f][rc][j]){
				v[f][id].pb(v[f][rc][j++]);
			}
			else{
				v[f][id].pb(v[f][lc][i++]);
			}
		}
	}
}

void build(int id=1,int s=1,int e=n){
	if(ln==1){
		mn[id]=mx[id]=x[s].F;
		v[0][id].pb(x[s].F+x[s].S);
		v[1][id].pb(x[s].S);
		return;
	}
	build(lc,s,md);
	build(rc,md+1,e);
	merge(id,0);
	merge(id,1);
	mn[id]=mn[lc];
	mx[id]=mx[rc];
}

void get(int f,int l,int r,int id=1,int s=1,int e=n){
	if(mn[id]>r || l>mx[id])return;
	if(mn[id]>=l && mx[id]<=r){
		int L=-1,R=ln;
		//cout<<id<<endl;
		int w;
		if(f==0)w=c;
		else w=b;
		while(R-L>1){
			int m=(L+R)/2;
			if(v[f][id][m]<w)L=m;
			else R=m;
		}
		//cout<<L<<" "<<R<<endl;
		ans+=ln-R;
		return;
	}
	get(f,l,r,lc,s,md);
	get(f,l,r,rc,md+1,e);
}

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>x[i].F>>x[i].S;
	}
	sort(x+1,x+n+1);
	build();
	while(q--){
		cin>>a>>b>>c;
		ans=0;
		get(0,a,c-b);
		get(1,max(a,c-b+1),1e9+7);
		cout<<ans<<endl;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19100 KB Output is correct
2 Correct 10 ms 19120 KB Output is correct
3 Correct 11 ms 19116 KB Output is correct
4 Correct 10 ms 19128 KB Output is correct
5 Correct 10 ms 19124 KB Output is correct
6 Correct 10 ms 19052 KB Output is correct
7 Correct 16 ms 20060 KB Output is correct
8 Correct 16 ms 19992 KB Output is correct
9 Correct 16 ms 20008 KB Output is correct
10 Correct 13 ms 20012 KB Output is correct
11 Correct 13 ms 19932 KB Output is correct
12 Correct 18 ms 19936 KB Output is correct
13 Correct 13 ms 20028 KB Output is correct
14 Correct 19 ms 20036 KB Output is correct
15 Correct 14 ms 19920 KB Output is correct
16 Correct 19 ms 19900 KB Output is correct
17 Correct 16 ms 20004 KB Output is correct
18 Correct 17 ms 19912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 265 ms 51344 KB Output is correct
2 Correct 275 ms 51416 KB Output is correct
3 Correct 291 ms 51428 KB Output is correct
4 Correct 237 ms 50668 KB Output is correct
5 Correct 163 ms 50584 KB Output is correct
6 Correct 193 ms 49932 KB Output is correct
7 Correct 256 ms 51308 KB Output is correct
8 Correct 267 ms 51344 KB Output is correct
9 Correct 236 ms 51256 KB Output is correct
10 Correct 137 ms 50460 KB Output is correct
11 Correct 234 ms 50496 KB Output is correct
12 Correct 132 ms 49532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 265 ms 51344 KB Output is correct
2 Correct 275 ms 51416 KB Output is correct
3 Correct 291 ms 51428 KB Output is correct
4 Correct 237 ms 50668 KB Output is correct
5 Correct 163 ms 50584 KB Output is correct
6 Correct 193 ms 49932 KB Output is correct
7 Correct 256 ms 51308 KB Output is correct
8 Correct 267 ms 51344 KB Output is correct
9 Correct 236 ms 51256 KB Output is correct
10 Correct 137 ms 50460 KB Output is correct
11 Correct 234 ms 50496 KB Output is correct
12 Correct 132 ms 49532 KB Output is correct
13 Correct 416 ms 51756 KB Output is correct
14 Correct 384 ms 51768 KB Output is correct
15 Correct 278 ms 51412 KB Output is correct
16 Correct 413 ms 51032 KB Output is correct
17 Correct 188 ms 51048 KB Output is correct
18 Correct 191 ms 49996 KB Output is correct
19 Correct 426 ms 51720 KB Output is correct
20 Correct 427 ms 51824 KB Output is correct
21 Correct 378 ms 51804 KB Output is correct
22 Correct 136 ms 50404 KB Output is correct
23 Correct 254 ms 50364 KB Output is correct
24 Correct 118 ms 49460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19100 KB Output is correct
2 Correct 10 ms 19120 KB Output is correct
3 Correct 11 ms 19116 KB Output is correct
4 Correct 10 ms 19128 KB Output is correct
5 Correct 10 ms 19124 KB Output is correct
6 Correct 10 ms 19052 KB Output is correct
7 Correct 16 ms 20060 KB Output is correct
8 Correct 16 ms 19992 KB Output is correct
9 Correct 16 ms 20008 KB Output is correct
10 Correct 13 ms 20012 KB Output is correct
11 Correct 13 ms 19932 KB Output is correct
12 Correct 18 ms 19936 KB Output is correct
13 Correct 13 ms 20028 KB Output is correct
14 Correct 19 ms 20036 KB Output is correct
15 Correct 14 ms 19920 KB Output is correct
16 Correct 19 ms 19900 KB Output is correct
17 Correct 16 ms 20004 KB Output is correct
18 Correct 17 ms 19912 KB Output is correct
19 Correct 265 ms 51344 KB Output is correct
20 Correct 275 ms 51416 KB Output is correct
21 Correct 291 ms 51428 KB Output is correct
22 Correct 237 ms 50668 KB Output is correct
23 Correct 163 ms 50584 KB Output is correct
24 Correct 193 ms 49932 KB Output is correct
25 Correct 256 ms 51308 KB Output is correct
26 Correct 267 ms 51344 KB Output is correct
27 Correct 236 ms 51256 KB Output is correct
28 Correct 137 ms 50460 KB Output is correct
29 Correct 234 ms 50496 KB Output is correct
30 Correct 132 ms 49532 KB Output is correct
31 Correct 416 ms 51756 KB Output is correct
32 Correct 384 ms 51768 KB Output is correct
33 Correct 278 ms 51412 KB Output is correct
34 Correct 413 ms 51032 KB Output is correct
35 Correct 188 ms 51048 KB Output is correct
36 Correct 191 ms 49996 KB Output is correct
37 Correct 426 ms 51720 KB Output is correct
38 Correct 427 ms 51824 KB Output is correct
39 Correct 378 ms 51804 KB Output is correct
40 Correct 136 ms 50404 KB Output is correct
41 Correct 254 ms 50364 KB Output is correct
42 Correct 118 ms 49460 KB Output is correct
43 Correct 374 ms 53712 KB Output is correct
44 Correct 398 ms 53708 KB Output is correct
45 Correct 339 ms 53732 KB Output is correct
46 Correct 355 ms 52156 KB Output is correct
47 Correct 202 ms 52216 KB Output is correct
48 Correct 172 ms 49780 KB Output is correct
49 Correct 395 ms 53612 KB Output is correct
50 Correct 369 ms 53604 KB Output is correct
51 Correct 506 ms 53480 KB Output is correct
52 Correct 137 ms 52032 KB Output is correct
53 Correct 270 ms 51228 KB Output is correct