Submission #461352

# Submission time Handle Problem Language Result Execution time Memory
461352 2021-08-09T23:21:56 Z zaneyu Examination (JOI19_examination) C++14
100 / 100
470 ms 76264 KB
 /*input
7 7
10000 100
70 70
45 15
2000 40
2000 95800 
6 70000
8000 10000
20 30000 0
2000 10 0
80 2999 0
0 100 0
70 600 0
1000 1000 0
4900 3500 0
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=1e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
pii arr[maxn];
pair<pii,pii> query[maxn];
struct node{
    ll sum=0;
    int lc=0,rc=0;
}seg[40*maxn];
//check this line
int tot=2;
inline void mdf(int &idx,ll l,ll r,int p,int x){
    if(r<p or l>p) return;
    if(!idx){
        idx=(tot++);
    }
    if(l==r){
        seg[idx].sum+=x;
        return;
    }
    int mid=(l+r)/2;
    mdf(seg[idx].lc,l,mid,p,x);
    mdf(seg[idx].rc,mid+1,r,p,x);
    seg[idx].sum=(seg[seg[idx].lc].sum+seg[seg[idx].rc].sum);
}
inline ll qq(int &idx,ll l,ll r,int ql,int qr){
    if(!idx){
        return 0;
    }
    if(r<ql or l>qr) return 0;
    if(ql<=l and r<=qr){
        return seg[idx].sum;
    }
    int mid=(l+r)/2;
    return (qq(seg[idx].lc,l,mid,ql,qr)+qq(seg[idx].rc,mid+1,r,ql,qr));
}
int rt=1;
inline void mdf(int p,int x){
	mdf(rt,0,2e9,p,x);
}
inline int qq(int l,int r){
	return qq(rt,0,2e9,l,r);
}
int ans[maxn];
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n,q;
    cin>>n>>q;
    //vector<int> dx,dy,dz;
    multiset<pii> stf;
    REP(i,n) cin>>arr[i].f>>arr[i].s,stf.insert({arr[i].s,arr[i].s+arr[i].f});
    vector<pair<pii,pii>> query,qb;

    REP(i,q){
    	pair<pii,pii> x;
    	cin>>x.f.f>>x.f.s>>x.s.f;
    	x.s.s=i;
    	if(x.f.f+x.f.s>=x.s.f) query.pb(x);
    	else qb.pb(x);
    }
    sort(ALL(query));
    sort(arr,arr+n);
    int p=n-1;
    for(int i=sz(query)-1;i>=0;i--){
    	while(p>=0 and arr[p].f>=query[i].f.f) mdf(2e9-arr[p].s,1),--p;
    	ans[query[i].s.s]=qq(0,2e9-query[i].f.s);
    }
  	sort(ALL(qb));
    REP(i,40*maxn) seg[i].sum=seg[i].lc=seg[i].rc=0;
    tot=2;
    p=n-1;
 	for(int i=sz(qb)-1;i>=0;i--){
    	while(p>=0 and arr[p].f>=qb[i].f.f) mdf(2e9-arr[p].s-arr[p].f,1),--p;
    	ans[qb[i].s.s]=qq(0,2e9-qb[i].s.f);
    	//cout<<qb[i].s.s<<' '<<ans[qb[i].s.s]<<'\n';
 	}
 	REP(i,40*maxn) seg[i].sum=seg[i].lc=seg[i].rc=0;
 	tot=2;
 	REP(i,n) swap(arr[i].f,arr[i].s);
 	sort(arr,arr+n);
 	REP(i,sz(qb)){
 		swap(qb[i].f.f,qb[i].f.s);
 	}
  	sort(ALL(qb));
  	p=0;
  	REP(i,sz(qb)){
    	while(p<n and arr[p].f<qb[i].f.f) mdf(2e9-arr[p].s-arr[p].f,1),++p;
    	ans[qb[i].s.s]-=qq(0,2e9-qb[i].s.f);
 	}
    REP(i,q) cout<<ans[i]<<'\n';
} 
# Verdict Execution time Memory Grader output
1 Correct 41 ms 62916 KB Output is correct
2 Correct 41 ms 62936 KB Output is correct
3 Correct 40 ms 62916 KB Output is correct
4 Correct 40 ms 62936 KB Output is correct
5 Correct 41 ms 62880 KB Output is correct
6 Correct 39 ms 62924 KB Output is correct
7 Correct 48 ms 63312 KB Output is correct
8 Correct 49 ms 63308 KB Output is correct
9 Correct 48 ms 63296 KB Output is correct
10 Correct 47 ms 63304 KB Output is correct
11 Correct 48 ms 63292 KB Output is correct
12 Correct 46 ms 63232 KB Output is correct
13 Correct 46 ms 63284 KB Output is correct
14 Correct 47 ms 63336 KB Output is correct
15 Correct 46 ms 63248 KB Output is correct
16 Correct 45 ms 63280 KB Output is correct
17 Correct 47 ms 63348 KB Output is correct
18 Correct 46 ms 63224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 241 ms 73460 KB Output is correct
2 Correct 240 ms 73556 KB Output is correct
3 Correct 246 ms 73516 KB Output is correct
4 Correct 203 ms 72836 KB Output is correct
5 Correct 231 ms 72784 KB Output is correct
6 Correct 182 ms 71996 KB Output is correct
7 Correct 238 ms 73388 KB Output is correct
8 Correct 238 ms 73392 KB Output is correct
9 Correct 240 ms 73308 KB Output is correct
10 Correct 193 ms 72648 KB Output is correct
11 Correct 189 ms 72532 KB Output is correct
12 Correct 150 ms 71608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 241 ms 73460 KB Output is correct
2 Correct 240 ms 73556 KB Output is correct
3 Correct 246 ms 73516 KB Output is correct
4 Correct 203 ms 72836 KB Output is correct
5 Correct 231 ms 72784 KB Output is correct
6 Correct 182 ms 71996 KB Output is correct
7 Correct 238 ms 73388 KB Output is correct
8 Correct 238 ms 73392 KB Output is correct
9 Correct 240 ms 73308 KB Output is correct
10 Correct 193 ms 72648 KB Output is correct
11 Correct 189 ms 72532 KB Output is correct
12 Correct 150 ms 71608 KB Output is correct
13 Correct 361 ms 73956 KB Output is correct
14 Correct 325 ms 74308 KB Output is correct
15 Correct 245 ms 73528 KB Output is correct
16 Correct 300 ms 73188 KB Output is correct
17 Correct 289 ms 73096 KB Output is correct
18 Correct 232 ms 72460 KB Output is correct
19 Correct 345 ms 73972 KB Output is correct
20 Correct 338 ms 73944 KB Output is correct
21 Correct 332 ms 74308 KB Output is correct
22 Correct 196 ms 72596 KB Output is correct
23 Correct 195 ms 72572 KB Output is correct
24 Correct 154 ms 71824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 62916 KB Output is correct
2 Correct 41 ms 62936 KB Output is correct
3 Correct 40 ms 62916 KB Output is correct
4 Correct 40 ms 62936 KB Output is correct
5 Correct 41 ms 62880 KB Output is correct
6 Correct 39 ms 62924 KB Output is correct
7 Correct 48 ms 63312 KB Output is correct
8 Correct 49 ms 63308 KB Output is correct
9 Correct 48 ms 63296 KB Output is correct
10 Correct 47 ms 63304 KB Output is correct
11 Correct 48 ms 63292 KB Output is correct
12 Correct 46 ms 63232 KB Output is correct
13 Correct 46 ms 63284 KB Output is correct
14 Correct 47 ms 63336 KB Output is correct
15 Correct 46 ms 63248 KB Output is correct
16 Correct 45 ms 63280 KB Output is correct
17 Correct 47 ms 63348 KB Output is correct
18 Correct 46 ms 63224 KB Output is correct
19 Correct 241 ms 73460 KB Output is correct
20 Correct 240 ms 73556 KB Output is correct
21 Correct 246 ms 73516 KB Output is correct
22 Correct 203 ms 72836 KB Output is correct
23 Correct 231 ms 72784 KB Output is correct
24 Correct 182 ms 71996 KB Output is correct
25 Correct 238 ms 73388 KB Output is correct
26 Correct 238 ms 73392 KB Output is correct
27 Correct 240 ms 73308 KB Output is correct
28 Correct 193 ms 72648 KB Output is correct
29 Correct 189 ms 72532 KB Output is correct
30 Correct 150 ms 71608 KB Output is correct
31 Correct 361 ms 73956 KB Output is correct
32 Correct 325 ms 74308 KB Output is correct
33 Correct 245 ms 73528 KB Output is correct
34 Correct 300 ms 73188 KB Output is correct
35 Correct 289 ms 73096 KB Output is correct
36 Correct 232 ms 72460 KB Output is correct
37 Correct 345 ms 73972 KB Output is correct
38 Correct 338 ms 73944 KB Output is correct
39 Correct 332 ms 74308 KB Output is correct
40 Correct 196 ms 72596 KB Output is correct
41 Correct 195 ms 72572 KB Output is correct
42 Correct 154 ms 71824 KB Output is correct
43 Correct 470 ms 75928 KB Output is correct
44 Correct 421 ms 75960 KB Output is correct
45 Correct 419 ms 76264 KB Output is correct
46 Correct 331 ms 74348 KB Output is correct
47 Correct 356 ms 74380 KB Output is correct
48 Correct 255 ms 72260 KB Output is correct
49 Correct 412 ms 75752 KB Output is correct
50 Correct 360 ms 76220 KB Output is correct
51 Correct 373 ms 75832 KB Output is correct
52 Correct 331 ms 74120 KB Output is correct
53 Correct 189 ms 73392 KB Output is correct