//#include<i_am_noob_orz>
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define pii pair<int,int>
#define X first
#define Y second
#define mod ((ll)1e9+7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define bit_count(x) __builtin_popcountll((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define jimmy_is_kind false
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
//#define LOCAL
#ifdef LOCAL
#define bug(...) cerr<<"#"<<__LINE__<<' '<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios_base::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif
int add(int a,int b){return(a+b>=mod?a+b-mod:a+b);}
int sub(int a,int b){return(a<b?a+mod-b:a-b);}
int po(int a,int b){
if(b==0)return 1;
if(b==1)return(a%mod);
int tem=po(a,b/2);
if(b&1)return(((tem*tem)%mod)*a)%mod;
else return(tem*tem)%mod;
}
int GCD(int a,int b){
int x=0;
int ra,rb;
while(a&&b){
if(((a&1)==0)&&((b&1)==0)){
a>>=1,b>>=1,x++;
}
else if((a^b)&1){
if(a&1)b>>=1;
else a>>=1;
}
else{
ra=abs(a-b),rb=min(a,b);
a=ra,b=rb;
}
}
return max(a,b)<<x;
}
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int balbit[200010],o[100010];
bool cmp1(pair<pii,pii> x,pair<pii,pii> y){
if(x.X.Y==y.X.Y){return x.Y.Y>=y.Y.Y;}
else return x.X.Y>y.X.Y;
}
bool cmp(pair<pii,pii> x,pair<pii,pii> y){
if(x.X.X==y.X.X){return x.Y.Y>=y.Y.Y;}
else return x.X.X>y.X.X;
}
void ADD(int x,int vl){
for(;x>0;x-=(x&(-x)))balbit[x]+=vl;
}
int QRY(int x){
int re=0;
for(;x<=200000;x+=(x&-x))re+=balbit[x];
return re;
}
void CDQ(int l,int r,vector<pair<pii,pii> >& a){
if(l==r)return;
int mi=(l+r)/2;
vector<pair<pii,pii> >lv,rv;
for(int i=l;i<=mi;i++)lv.pb(a[i-l]);
for(int i=mi+1;i<=r;i++)rv.pb(a[i-l]);
CDQ(l,mi,lv),CDQ(mi+1,r,rv);
//for(auto &pt:lv)cout<<"lv "<<l<<" "<<r<<" "<<pt.X.X<<" "<<pt.X.Y<<" "<<pt.Y.X<<" "<<pt.Y.Y<<endl;
//for(auto &pt:rv)cout<<"rv "<<l<<" "<<r<<" "<<pt.X.X<<" "<<pt.X.Y<<" "<<pt.Y.X<<" "<<pt.Y.Y<<endl;
vector<pair<pii,pii> > b;
vector<int> rem;
int pl=0,pr=0;
while(pl<sz(lv)&&pr<sz(rv)){
if(cmp1(lv[pl],rv[pr])){
if(lv[pl].Y.Y>=0){
ADD(lv[pl].Y.X,1);
rem.pb(lv[pl].Y.X);
}
b.pb(lv[pl]);
pl++;
}
else{
if(rv[pr].Y.Y<0){
o[-rv[pr].Y.Y]+=QRY(rv[pr].Y.X);
bug(-rv[pr].Y.Y,QRY(rv[pr].Y.X));
}
b.pb(rv[pr]);
pr++;
}
}
while(pl<sz(lv)){
if(lv[pl].Y.Y>=0){
ADD(lv[pl].Y.X,1);
rem.pb(lv[pl].Y.X);
}
b.pb(lv[pl]);
pl++;
}
while(pr<sz(rv)){
if(rv[pr].Y.Y<0){
o[-rv[pr].Y.Y]+=QRY(rv[pr].Y.X);
bug(-rv[pr].Y.Y,QRY(rv[pr].Y.X));
}
b.pb(rv[pr]);
pr++;
}
for(int x:rem)ADD(x,-1);
assert(sz(a)==sz(b));
F(sz(a))a[i]=b[i];
return;
}
signed main(){
IOS();
int n,q;
cin>>n>>q;
vector<pair<pii,pii> > ar;
vector<int> v;
map<int,int> m;
memres(o);
F(n){
int x,y;
cin>>x>>y;
ar.pb({{x,y},{x+y,i}});
v.pb(x+y);
}
F(q){
int x,y,z;
cin>>x>>y>>z;
ar.pb({{x,y},{z,-i-1}});
v.pb(z);
}
sort(all(v));
v.resize(unique(all(v))-v.begin());
F(sz(v))m[v[i]]=i+1;
for(auto &pt:ar)pt.Y.X=m[pt.Y.X];
sort(all(ar),cmp);
//for(auto &pt:ar)cout<<pt.X.X<<" "<<pt.X.Y<<" "<<pt.Y.X<<" "<<pt.Y.Y<<endl;
CDQ(0,n+q-1,ar);
F(q)cout<<o[i+1]<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1092 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
12 ms |
2568 KB |
Output is correct |
8 |
Correct |
12 ms |
2572 KB |
Output is correct |
9 |
Correct |
13 ms |
2596 KB |
Output is correct |
10 |
Correct |
12 ms |
2568 KB |
Output is correct |
11 |
Correct |
11 ms |
2568 KB |
Output is correct |
12 |
Correct |
9 ms |
2052 KB |
Output is correct |
13 |
Correct |
11 ms |
2444 KB |
Output is correct |
14 |
Correct |
11 ms |
2444 KB |
Output is correct |
15 |
Correct |
11 ms |
2444 KB |
Output is correct |
16 |
Correct |
10 ms |
2316 KB |
Output is correct |
17 |
Correct |
12 ms |
2516 KB |
Output is correct |
18 |
Correct |
8 ms |
2064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
400 ms |
41512 KB |
Output is correct |
2 |
Correct |
396 ms |
41572 KB |
Output is correct |
3 |
Correct |
418 ms |
41548 KB |
Output is correct |
4 |
Correct |
370 ms |
40160 KB |
Output is correct |
5 |
Correct |
368 ms |
40152 KB |
Output is correct |
6 |
Correct |
298 ms |
35296 KB |
Output is correct |
7 |
Correct |
378 ms |
41472 KB |
Output is correct |
8 |
Correct |
382 ms |
41440 KB |
Output is correct |
9 |
Correct |
383 ms |
41364 KB |
Output is correct |
10 |
Correct |
369 ms |
40032 KB |
Output is correct |
11 |
Correct |
371 ms |
40316 KB |
Output is correct |
12 |
Correct |
246 ms |
35272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
400 ms |
41512 KB |
Output is correct |
2 |
Correct |
396 ms |
41572 KB |
Output is correct |
3 |
Correct |
418 ms |
41548 KB |
Output is correct |
4 |
Correct |
370 ms |
40160 KB |
Output is correct |
5 |
Correct |
368 ms |
40152 KB |
Output is correct |
6 |
Correct |
298 ms |
35296 KB |
Output is correct |
7 |
Correct |
378 ms |
41472 KB |
Output is correct |
8 |
Correct |
382 ms |
41440 KB |
Output is correct |
9 |
Correct |
383 ms |
41364 KB |
Output is correct |
10 |
Correct |
369 ms |
40032 KB |
Output is correct |
11 |
Correct |
371 ms |
40316 KB |
Output is correct |
12 |
Correct |
246 ms |
35272 KB |
Output is correct |
13 |
Correct |
473 ms |
45664 KB |
Output is correct |
14 |
Correct |
449 ms |
44768 KB |
Output is correct |
15 |
Correct |
389 ms |
41572 KB |
Output is correct |
16 |
Correct |
418 ms |
42284 KB |
Output is correct |
17 |
Correct |
402 ms |
42148 KB |
Output is correct |
18 |
Correct |
291 ms |
35428 KB |
Output is correct |
19 |
Correct |
472 ms |
45512 KB |
Output is correct |
20 |
Correct |
455 ms |
45048 KB |
Output is correct |
21 |
Correct |
455 ms |
45556 KB |
Output is correct |
22 |
Correct |
361 ms |
40012 KB |
Output is correct |
23 |
Correct |
355 ms |
40052 KB |
Output is correct |
24 |
Correct |
253 ms |
35352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1092 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
12 ms |
2568 KB |
Output is correct |
8 |
Correct |
12 ms |
2572 KB |
Output is correct |
9 |
Correct |
13 ms |
2596 KB |
Output is correct |
10 |
Correct |
12 ms |
2568 KB |
Output is correct |
11 |
Correct |
11 ms |
2568 KB |
Output is correct |
12 |
Correct |
9 ms |
2052 KB |
Output is correct |
13 |
Correct |
11 ms |
2444 KB |
Output is correct |
14 |
Correct |
11 ms |
2444 KB |
Output is correct |
15 |
Correct |
11 ms |
2444 KB |
Output is correct |
16 |
Correct |
10 ms |
2316 KB |
Output is correct |
17 |
Correct |
12 ms |
2516 KB |
Output is correct |
18 |
Correct |
8 ms |
2064 KB |
Output is correct |
19 |
Correct |
400 ms |
41512 KB |
Output is correct |
20 |
Correct |
396 ms |
41572 KB |
Output is correct |
21 |
Correct |
418 ms |
41548 KB |
Output is correct |
22 |
Correct |
370 ms |
40160 KB |
Output is correct |
23 |
Correct |
368 ms |
40152 KB |
Output is correct |
24 |
Correct |
298 ms |
35296 KB |
Output is correct |
25 |
Correct |
378 ms |
41472 KB |
Output is correct |
26 |
Correct |
382 ms |
41440 KB |
Output is correct |
27 |
Correct |
383 ms |
41364 KB |
Output is correct |
28 |
Correct |
369 ms |
40032 KB |
Output is correct |
29 |
Correct |
371 ms |
40316 KB |
Output is correct |
30 |
Correct |
246 ms |
35272 KB |
Output is correct |
31 |
Correct |
473 ms |
45664 KB |
Output is correct |
32 |
Correct |
449 ms |
44768 KB |
Output is correct |
33 |
Correct |
389 ms |
41572 KB |
Output is correct |
34 |
Correct |
418 ms |
42284 KB |
Output is correct |
35 |
Correct |
402 ms |
42148 KB |
Output is correct |
36 |
Correct |
291 ms |
35428 KB |
Output is correct |
37 |
Correct |
472 ms |
45512 KB |
Output is correct |
38 |
Correct |
455 ms |
45048 KB |
Output is correct |
39 |
Correct |
455 ms |
45556 KB |
Output is correct |
40 |
Correct |
361 ms |
40012 KB |
Output is correct |
41 |
Correct |
355 ms |
40052 KB |
Output is correct |
42 |
Correct |
253 ms |
35352 KB |
Output is correct |
43 |
Correct |
560 ms |
52964 KB |
Output is correct |
44 |
Correct |
547 ms |
52832 KB |
Output is correct |
45 |
Correct |
521 ms |
52828 KB |
Output is correct |
46 |
Correct |
535 ms |
51360 KB |
Output is correct |
47 |
Correct |
531 ms |
51208 KB |
Output is correct |
48 |
Correct |
289 ms |
35484 KB |
Output is correct |
49 |
Correct |
498 ms |
52748 KB |
Output is correct |
50 |
Correct |
529 ms |
52704 KB |
Output is correct |
51 |
Correct |
518 ms |
52836 KB |
Output is correct |
52 |
Correct |
517 ms |
51284 KB |
Output is correct |
53 |
Correct |
389 ms |
43496 KB |
Output is correct |