#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<pll,pll> tyty;
const ll N=1e6+5;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define lwb lower_bound
#define Y second
#define SZ(a) (ll)a.size()
ll bit[N],n,q,s,t,a,b,c,ans[N];
vector<tyty> v;
vector<ll> lis;
void add(ll id,ll d){
while(id<N)bit[id]+=d,id+=(id&-id);
}
ll Q(ll id){
ll tmp=0;
while(id)tmp+=bit[id],id-=(id&-id);
return tmp;
}
void CDQ(ll l,ll r){
//cout<<l<<" "<<r<<"\n";
if(r==l+1)return;
ll mid=(l+r)/2;
CDQ(l,mid);CDQ(mid,r);
ll ql=l,qr=mid;
vector<ll> que;
while(ql<mid&&qr<r){
if(v[ql].X.Y<=v[qr].X.Y){
if(v[ql].Y.Y==0)add(v[ql].Y.X,1),que.pb(v[ql].Y.X);
++ql;
}else{
if(v[qr].Y.Y!=0)ans[v[qr].Y.Y]+=Q(v[qr].Y.X);
++qr;
}
}
//while(ql<mid)
while(qr<r)if(v[qr].Y.Y!=0)ans[v[qr].Y.Y]+=Q(v[qr].Y.X),++qr;else ++qr;
for(ll i:que){add(i,-1);}
sort(v.begin()+l,v.begin()+r,[](tyty a,tyty b){return (a.X.Y!=b.X.Y?a.X.Y<b.X.Y:a.Y.Y<b.Y.Y);});
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>q;
REP(i,n)cin>>s>>t,v.pb(mp(mp(-s,-t),mp(-(s+t),0))),lis.pb(-s),lis.pb(-t),lis.pb(-s-t);
REP1(i,q)cin>>a>>b>>c,v.pb(mp(mp(-a,-b),mp(-c,i))),lis.pb(-a),lis.pb(-b),lis.pb(-c);
sort(lis.begin(),lis.end());
lis.resize(unique(lis.begin(),lis.end())-lis.begin());
for(auto &i:v){
i.X.X=lwb(lis.begin(),lis.end(),i.X.X)-lis.begin()+1;
i.X.Y=lwb(lis.begin(),lis.end(),i.X.Y)-lis.begin()+1;
i.Y.X=lwb(lis.begin(),lis.end(),i.Y.X)-lis.begin()+1;
}
sort(v.begin(),v.end());
CDQ(0,SZ(v));
REP1(i,q)cout<<ans[i]<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
380 KB |
Output is correct |
4 |
Correct |
5 ms |
380 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
18 ms |
1268 KB |
Output is correct |
8 |
Correct |
17 ms |
1140 KB |
Output is correct |
9 |
Correct |
17 ms |
1268 KB |
Output is correct |
10 |
Correct |
15 ms |
1140 KB |
Output is correct |
11 |
Correct |
15 ms |
1140 KB |
Output is correct |
12 |
Correct |
13 ms |
1012 KB |
Output is correct |
13 |
Correct |
16 ms |
1268 KB |
Output is correct |
14 |
Correct |
16 ms |
1268 KB |
Output is correct |
15 |
Correct |
17 ms |
1268 KB |
Output is correct |
16 |
Correct |
13 ms |
1140 KB |
Output is correct |
17 |
Correct |
15 ms |
1140 KB |
Output is correct |
18 |
Correct |
11 ms |
1012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
556 ms |
14816 KB |
Output is correct |
2 |
Correct |
547 ms |
17196 KB |
Output is correct |
3 |
Correct |
543 ms |
15148 KB |
Output is correct |
4 |
Correct |
422 ms |
14756 KB |
Output is correct |
5 |
Correct |
441 ms |
14896 KB |
Output is correct |
6 |
Correct |
339 ms |
14656 KB |
Output is correct |
7 |
Correct |
526 ms |
16036 KB |
Output is correct |
8 |
Correct |
530 ms |
15140 KB |
Output is correct |
9 |
Correct |
523 ms |
15908 KB |
Output is correct |
10 |
Correct |
373 ms |
14656 KB |
Output is correct |
11 |
Correct |
405 ms |
14652 KB |
Output is correct |
12 |
Correct |
307 ms |
14648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
556 ms |
14816 KB |
Output is correct |
2 |
Correct |
547 ms |
17196 KB |
Output is correct |
3 |
Correct |
543 ms |
15148 KB |
Output is correct |
4 |
Correct |
422 ms |
14756 KB |
Output is correct |
5 |
Correct |
441 ms |
14896 KB |
Output is correct |
6 |
Correct |
339 ms |
14656 KB |
Output is correct |
7 |
Correct |
526 ms |
16036 KB |
Output is correct |
8 |
Correct |
530 ms |
15140 KB |
Output is correct |
9 |
Correct |
523 ms |
15908 KB |
Output is correct |
10 |
Correct |
373 ms |
14656 KB |
Output is correct |
11 |
Correct |
405 ms |
14652 KB |
Output is correct |
12 |
Correct |
307 ms |
14648 KB |
Output is correct |
13 |
Correct |
578 ms |
15224 KB |
Output is correct |
14 |
Correct |
582 ms |
15040 KB |
Output is correct |
15 |
Correct |
540 ms |
15108 KB |
Output is correct |
16 |
Correct |
462 ms |
14892 KB |
Output is correct |
17 |
Correct |
446 ms |
14756 KB |
Output is correct |
18 |
Correct |
366 ms |
14792 KB |
Output is correct |
19 |
Correct |
586 ms |
15280 KB |
Output is correct |
20 |
Correct |
579 ms |
15140 KB |
Output is correct |
21 |
Correct |
550 ms |
15908 KB |
Output is correct |
22 |
Correct |
374 ms |
14656 KB |
Output is correct |
23 |
Correct |
407 ms |
14652 KB |
Output is correct |
24 |
Correct |
315 ms |
14656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
380 KB |
Output is correct |
4 |
Correct |
5 ms |
380 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
18 ms |
1268 KB |
Output is correct |
8 |
Correct |
17 ms |
1140 KB |
Output is correct |
9 |
Correct |
17 ms |
1268 KB |
Output is correct |
10 |
Correct |
15 ms |
1140 KB |
Output is correct |
11 |
Correct |
15 ms |
1140 KB |
Output is correct |
12 |
Correct |
13 ms |
1012 KB |
Output is correct |
13 |
Correct |
16 ms |
1268 KB |
Output is correct |
14 |
Correct |
16 ms |
1268 KB |
Output is correct |
15 |
Correct |
17 ms |
1268 KB |
Output is correct |
16 |
Correct |
13 ms |
1140 KB |
Output is correct |
17 |
Correct |
15 ms |
1140 KB |
Output is correct |
18 |
Correct |
11 ms |
1012 KB |
Output is correct |
19 |
Correct |
556 ms |
14816 KB |
Output is correct |
20 |
Correct |
547 ms |
17196 KB |
Output is correct |
21 |
Correct |
543 ms |
15148 KB |
Output is correct |
22 |
Correct |
422 ms |
14756 KB |
Output is correct |
23 |
Correct |
441 ms |
14896 KB |
Output is correct |
24 |
Correct |
339 ms |
14656 KB |
Output is correct |
25 |
Correct |
526 ms |
16036 KB |
Output is correct |
26 |
Correct |
530 ms |
15140 KB |
Output is correct |
27 |
Correct |
523 ms |
15908 KB |
Output is correct |
28 |
Correct |
373 ms |
14656 KB |
Output is correct |
29 |
Correct |
405 ms |
14652 KB |
Output is correct |
30 |
Correct |
307 ms |
14648 KB |
Output is correct |
31 |
Correct |
578 ms |
15224 KB |
Output is correct |
32 |
Correct |
582 ms |
15040 KB |
Output is correct |
33 |
Correct |
540 ms |
15108 KB |
Output is correct |
34 |
Correct |
462 ms |
14892 KB |
Output is correct |
35 |
Correct |
446 ms |
14756 KB |
Output is correct |
36 |
Correct |
366 ms |
14792 KB |
Output is correct |
37 |
Correct |
586 ms |
15280 KB |
Output is correct |
38 |
Correct |
579 ms |
15140 KB |
Output is correct |
39 |
Correct |
550 ms |
15908 KB |
Output is correct |
40 |
Correct |
374 ms |
14656 KB |
Output is correct |
41 |
Correct |
407 ms |
14652 KB |
Output is correct |
42 |
Correct |
315 ms |
14656 KB |
Output is correct |
43 |
Correct |
649 ms |
18728 KB |
Output is correct |
44 |
Correct |
632 ms |
18756 KB |
Output is correct |
45 |
Correct |
631 ms |
18740 KB |
Output is correct |
46 |
Correct |
484 ms |
17188 KB |
Output is correct |
47 |
Correct |
479 ms |
17068 KB |
Output is correct |
48 |
Correct |
371 ms |
14652 KB |
Output is correct |
49 |
Correct |
595 ms |
19376 KB |
Output is correct |
50 |
Correct |
599 ms |
18552 KB |
Output is correct |
51 |
Correct |
606 ms |
19120 KB |
Output is correct |
52 |
Correct |
399 ms |
16048 KB |
Output is correct |
53 |
Correct |
405 ms |
15408 KB |
Output is correct |