Submission #630314

# Submission time Handle Problem Language Result Execution time Memory
630314 2022-08-16T07:38:00 Z codr0 Examination (JOI19_examination) C++14
100 / 100
2050 ms 199096 KB
// Code by Parsa Eslami

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define bit(i,j) ((j>>i)&1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define err(x) cerr<<#x<<" : "<<x<<'\n'
#define dmid int mid=(r+l)/2
#define lc 2*id
#define rc 2*id+1

using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=2e5+4;
const int inf=1e9+1;
ordered_set<pii> seg[4*N];

	void upd(int id,int l,int r,int ind,pii x){
		if(ind>=r||ind<l) return;
		seg[id].insert(x);
		if(l+1==r) return;
		dmid;
		upd(lc,l,mid,ind,x);
		upd(rc,mid,r,ind,x);
	}

	int get(int id,int l,int r,int st,int en,int y){
		if(st>=r||en<=l) return 0;
		if(st<=l&&en>=r) return (seg[id].order_of_key({inf,0})-seg[id].order_of_key({y,0}));
		dmid;
		return (get(lc,l,mid,st,en,y)+get(rc,mid,r,st,en,y));
	}

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

	int n,q; cin>>n>>q;
	int a[n+1],b[n+1],c[n+1];
	FOR(i,1,n){ cin>>a[i]>>b[i]; c[i]=a[i]+b[i];}
	int X[q+1],Y[q+1],S[q+1];
	FOR(i,1,q) cin>>X[i]>>Y[i]>>S[i];
	vector<pii> vc;
	FOR(i,1,n) vc.pb({a[i],2*i});
	FOR(i,1,q) vc.pb({X[i],2*i+1});
	sort(all(vc));
	int comp=0;
	FOR(i,0,SZ(vc)-1){
		if(i==0||vc[i].F!=vc[i-1].F) comp++;
		if(vc[i].S&1) X[vc[i].S/2]=comp;
		else a[vc[i].S/2]=comp;
	}
	int ans[q+1]={};
	vector<pii> vc0;
	vector<pii> vc1;
	FOR(i,1,n) vc0.pb({c[i],i});
	FOR(i,1,q) vc1.pb({S[i],i});
	sort(all(vc0)); sort(all(vc1));
	while(!vc1.empty()){
		while(!vc0.empty()&&vc0.back().F>=vc1.back().F){
			int i=vc0.back().S;
			upd(1,1,n+q+1,a[i],{b[i],i});
			vc0.pop_back();
		}
		int i=vc1.back().S;
		ans[i]=get(1,1,n+q+1,X[i],n+q+1,Y[i]);
		vc1.pop_back();
	}
	FOR(i,1,q) cout<<ans[i]<<'\n';

	return 0;
	}
# Verdict Execution time Memory Grader output
1 Correct 54 ms 75340 KB Output is correct
2 Correct 52 ms 75344 KB Output is correct
3 Correct 52 ms 75336 KB Output is correct
4 Correct 54 ms 75340 KB Output is correct
5 Correct 51 ms 75448 KB Output is correct
6 Correct 52 ms 75448 KB Output is correct
7 Correct 67 ms 78216 KB Output is correct
8 Correct 68 ms 78212 KB Output is correct
9 Correct 69 ms 78212 KB Output is correct
10 Correct 68 ms 78244 KB Output is correct
11 Correct 67 ms 78160 KB Output is correct
12 Correct 67 ms 78204 KB Output is correct
13 Correct 67 ms 78132 KB Output is correct
14 Correct 67 ms 78200 KB Output is correct
15 Correct 69 ms 78216 KB Output is correct
16 Correct 66 ms 78068 KB Output is correct
17 Correct 72 ms 78216 KB Output is correct
18 Correct 65 ms 77968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1974 ms 198836 KB Output is correct
2 Correct 2015 ms 198880 KB Output is correct
3 Correct 1895 ms 198972 KB Output is correct
4 Correct 1260 ms 198896 KB Output is correct
5 Correct 1130 ms 198480 KB Output is correct
6 Correct 894 ms 198544 KB Output is correct
7 Correct 1802 ms 198924 KB Output is correct
8 Correct 1762 ms 198968 KB Output is correct
9 Correct 1621 ms 198912 KB Output is correct
10 Correct 1487 ms 194664 KB Output is correct
11 Correct 1100 ms 198888 KB Output is correct
12 Correct 1429 ms 194408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1974 ms 198836 KB Output is correct
2 Correct 2015 ms 198880 KB Output is correct
3 Correct 1895 ms 198972 KB Output is correct
4 Correct 1260 ms 198896 KB Output is correct
5 Correct 1130 ms 198480 KB Output is correct
6 Correct 894 ms 198544 KB Output is correct
7 Correct 1802 ms 198924 KB Output is correct
8 Correct 1762 ms 198968 KB Output is correct
9 Correct 1621 ms 198912 KB Output is correct
10 Correct 1487 ms 194664 KB Output is correct
11 Correct 1100 ms 198888 KB Output is correct
12 Correct 1429 ms 194408 KB Output is correct
13 Correct 1838 ms 198900 KB Output is correct
14 Correct 2050 ms 199016 KB Output is correct
15 Correct 1957 ms 199028 KB Output is correct
16 Correct 1236 ms 198940 KB Output is correct
17 Correct 1128 ms 198572 KB Output is correct
18 Correct 947 ms 198616 KB Output is correct
19 Correct 1788 ms 198964 KB Output is correct
20 Correct 1942 ms 199028 KB Output is correct
21 Correct 1637 ms 198848 KB Output is correct
22 Correct 1460 ms 194488 KB Output is correct
23 Correct 1097 ms 198708 KB Output is correct
24 Correct 1415 ms 194268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 75340 KB Output is correct
2 Correct 52 ms 75344 KB Output is correct
3 Correct 52 ms 75336 KB Output is correct
4 Correct 54 ms 75340 KB Output is correct
5 Correct 51 ms 75448 KB Output is correct
6 Correct 52 ms 75448 KB Output is correct
7 Correct 67 ms 78216 KB Output is correct
8 Correct 68 ms 78212 KB Output is correct
9 Correct 69 ms 78212 KB Output is correct
10 Correct 68 ms 78244 KB Output is correct
11 Correct 67 ms 78160 KB Output is correct
12 Correct 67 ms 78204 KB Output is correct
13 Correct 67 ms 78132 KB Output is correct
14 Correct 67 ms 78200 KB Output is correct
15 Correct 69 ms 78216 KB Output is correct
16 Correct 66 ms 78068 KB Output is correct
17 Correct 72 ms 78216 KB Output is correct
18 Correct 65 ms 77968 KB Output is correct
19 Correct 1974 ms 198836 KB Output is correct
20 Correct 2015 ms 198880 KB Output is correct
21 Correct 1895 ms 198972 KB Output is correct
22 Correct 1260 ms 198896 KB Output is correct
23 Correct 1130 ms 198480 KB Output is correct
24 Correct 894 ms 198544 KB Output is correct
25 Correct 1802 ms 198924 KB Output is correct
26 Correct 1762 ms 198968 KB Output is correct
27 Correct 1621 ms 198912 KB Output is correct
28 Correct 1487 ms 194664 KB Output is correct
29 Correct 1100 ms 198888 KB Output is correct
30 Correct 1429 ms 194408 KB Output is correct
31 Correct 1838 ms 198900 KB Output is correct
32 Correct 2050 ms 199016 KB Output is correct
33 Correct 1957 ms 199028 KB Output is correct
34 Correct 1236 ms 198940 KB Output is correct
35 Correct 1128 ms 198572 KB Output is correct
36 Correct 947 ms 198616 KB Output is correct
37 Correct 1788 ms 198964 KB Output is correct
38 Correct 1942 ms 199028 KB Output is correct
39 Correct 1637 ms 198848 KB Output is correct
40 Correct 1460 ms 194488 KB Output is correct
41 Correct 1097 ms 198708 KB Output is correct
42 Correct 1415 ms 194268 KB Output is correct
43 Correct 1773 ms 198912 KB Output is correct
44 Correct 1753 ms 199096 KB Output is correct
45 Correct 2021 ms 198884 KB Output is correct
46 Correct 1157 ms 198880 KB Output is correct
47 Correct 1163 ms 198572 KB Output is correct
48 Correct 881 ms 198388 KB Output is correct
49 Correct 1659 ms 198980 KB Output is correct
50 Correct 1643 ms 198876 KB Output is correct
51 Correct 1558 ms 199016 KB Output is correct
52 Correct 1430 ms 194512 KB Output is correct
53 Correct 1065 ms 198772 KB Output is correct