#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<
pair<int, int>,
null_type,
less_equal<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const long long MAXN = 5e5+5;
long long ans[MAXN];
long long seg[4*MAXN];
struct student{
long long type,x,y,z;
};
student hold[MAXN];
long long n,q;
bool sortfirst(student a,student b){
if(a.x==b.x){
return a.type>b.type;
}
return a.x<b.x;
}
bool sortsecond(student a,student b){
if(a.y==b.y){
return a.type>b.type;
}
return a.y<b.y;
}
bool sortthird(student a,student b){
if(a.z==b.z){
return a.type>b.type;
}
return a.z<b.z;
}
vector<student> v1;
void f(long long l,long long r){
v1.clear();
long long mid =(l+r)/2;
for(long long i=l;i<=mid;i++){
if(hold[i].type != 1){
v1.push_back(hold[i]);
}
}
for(long long i=mid+1;i<=r;i++){
if(hold[i].type == 1){
v1.push_back(hold[i]);
}
}
sort(v1.begin(),v1.end(),sortfirst);
ordered_set s1;
int cnt = 0;
for(long long i=v1.size()-1;i>=0;i--){
if(v1[i].type == 1){
s1.insert(make_pair(v1[i].y,cnt++));
//cout<<v1[i].y<<endl;
}else{
ans[v1[i].type]+=s1.size()-s1.order_of_key(make_pair(v1[i].y,0));
// cout<<l<<" "<<r<<" "<<" "<<v1[i].type<<" "<<ans[v1[i].type]<<endl;
}
}
if(l!=mid){
f(l,mid);
}
if(r!=mid+1){
f(mid+1,r);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>q;
//cout<<n<<" "<<q<<endl;
for(long long i=1;i<=n;i++){
long long s,t;
cin>>s>>t;
hold[i].type = 1;
hold[i].x=s;
hold[i].y=t;
hold[i].z=s+t;
}
for(long long i=n+1;i<=n+q;i++){
long long u,v,w;
cin>>u>>v>>w;
hold[i].type=i;
hold[i].x=u;
hold[i].y=v;
hold[i].z=w;
//queries.push_back(make_pair(make_pair(x,y),z));
}
sort(hold+1,hold+n+q+1,sortfirst);
long long curr = 1;
for(long long i=1;i<=n+q;i++){
while(i<=n+q && hold[i].x==hold[i+1].x){
hold[i].x=curr;
i++;
}
hold[i].x = curr;
curr++;
}
// cout<<curr<<endl;
curr=1;
sort(hold+1,hold+n+q+1,sortsecond);
for(long long i=1;i<=n+q;i++){
while(i<=n+q && hold[i].y==hold[i+1].y){
hold[i].y=curr;
i++;
}
hold[i].y=curr;
// cout<<hold[i].y<<endl;
curr++;
}
//cout<<curr<<endl;
sort(hold+1,hold+n+q+1,sortthird);
curr = 1;
for(long long i=1;i<=n+q;i++){
while(i<=n+q && hold[i].z==hold[i+1].z){
hold[i].z=curr;
i++;
}
hold[i].z = curr;
//cout<<hold[i].z<<endl;
curr++;
}
// cout<<curr<<endl;
f(1,n+q);
for(long long i=n+1;i<=n+q;i++){
cout<<ans[i]<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
16 ms |
1016 KB |
Output is correct |
8 |
Correct |
16 ms |
1016 KB |
Output is correct |
9 |
Correct |
16 ms |
1016 KB |
Output is correct |
10 |
Correct |
15 ms |
888 KB |
Output is correct |
11 |
Correct |
16 ms |
888 KB |
Output is correct |
12 |
Correct |
14 ms |
888 KB |
Output is correct |
13 |
Correct |
17 ms |
1272 KB |
Output is correct |
14 |
Correct |
17 ms |
1272 KB |
Output is correct |
15 |
Correct |
16 ms |
1272 KB |
Output is correct |
16 |
Correct |
14 ms |
1272 KB |
Output is correct |
17 |
Correct |
14 ms |
888 KB |
Output is correct |
18 |
Correct |
12 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
618 ms |
29268 KB |
Output is correct |
2 |
Correct |
613 ms |
29268 KB |
Output is correct |
3 |
Correct |
611 ms |
29272 KB |
Output is correct |
4 |
Correct |
545 ms |
28500 KB |
Output is correct |
5 |
Correct |
571 ms |
28496 KB |
Output is correct |
6 |
Correct |
476 ms |
27732 KB |
Output is correct |
7 |
Correct |
623 ms |
29140 KB |
Output is correct |
8 |
Correct |
595 ms |
29140 KB |
Output is correct |
9 |
Correct |
585 ms |
29140 KB |
Output is correct |
10 |
Correct |
508 ms |
28376 KB |
Output is correct |
11 |
Correct |
574 ms |
28376 KB |
Output is correct |
12 |
Correct |
494 ms |
27476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
618 ms |
29268 KB |
Output is correct |
2 |
Correct |
613 ms |
29268 KB |
Output is correct |
3 |
Correct |
611 ms |
29272 KB |
Output is correct |
4 |
Correct |
545 ms |
28500 KB |
Output is correct |
5 |
Correct |
571 ms |
28496 KB |
Output is correct |
6 |
Correct |
476 ms |
27732 KB |
Output is correct |
7 |
Correct |
623 ms |
29140 KB |
Output is correct |
8 |
Correct |
595 ms |
29140 KB |
Output is correct |
9 |
Correct |
585 ms |
29140 KB |
Output is correct |
10 |
Correct |
508 ms |
28376 KB |
Output is correct |
11 |
Correct |
574 ms |
28376 KB |
Output is correct |
12 |
Correct |
494 ms |
27476 KB |
Output is correct |
13 |
Correct |
584 ms |
21088 KB |
Output is correct |
14 |
Correct |
628 ms |
26292 KB |
Output is correct |
15 |
Correct |
587 ms |
29268 KB |
Output is correct |
16 |
Correct |
552 ms |
19552 KB |
Output is correct |
17 |
Correct |
570 ms |
19592 KB |
Output is correct |
18 |
Correct |
499 ms |
24380 KB |
Output is correct |
19 |
Correct |
573 ms |
21088 KB |
Output is correct |
20 |
Correct |
594 ms |
23012 KB |
Output is correct |
21 |
Correct |
568 ms |
21088 KB |
Output is correct |
22 |
Correct |
506 ms |
28372 KB |
Output is correct |
23 |
Correct |
565 ms |
28372 KB |
Output is correct |
24 |
Correct |
503 ms |
27348 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 |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
16 ms |
1016 KB |
Output is correct |
8 |
Correct |
16 ms |
1016 KB |
Output is correct |
9 |
Correct |
16 ms |
1016 KB |
Output is correct |
10 |
Correct |
15 ms |
888 KB |
Output is correct |
11 |
Correct |
16 ms |
888 KB |
Output is correct |
12 |
Correct |
14 ms |
888 KB |
Output is correct |
13 |
Correct |
17 ms |
1272 KB |
Output is correct |
14 |
Correct |
17 ms |
1272 KB |
Output is correct |
15 |
Correct |
16 ms |
1272 KB |
Output is correct |
16 |
Correct |
14 ms |
1272 KB |
Output is correct |
17 |
Correct |
14 ms |
888 KB |
Output is correct |
18 |
Correct |
12 ms |
888 KB |
Output is correct |
19 |
Correct |
618 ms |
29268 KB |
Output is correct |
20 |
Correct |
613 ms |
29268 KB |
Output is correct |
21 |
Correct |
611 ms |
29272 KB |
Output is correct |
22 |
Correct |
545 ms |
28500 KB |
Output is correct |
23 |
Correct |
571 ms |
28496 KB |
Output is correct |
24 |
Correct |
476 ms |
27732 KB |
Output is correct |
25 |
Correct |
623 ms |
29140 KB |
Output is correct |
26 |
Correct |
595 ms |
29140 KB |
Output is correct |
27 |
Correct |
585 ms |
29140 KB |
Output is correct |
28 |
Correct |
508 ms |
28376 KB |
Output is correct |
29 |
Correct |
574 ms |
28376 KB |
Output is correct |
30 |
Correct |
494 ms |
27476 KB |
Output is correct |
31 |
Correct |
584 ms |
21088 KB |
Output is correct |
32 |
Correct |
628 ms |
26292 KB |
Output is correct |
33 |
Correct |
587 ms |
29268 KB |
Output is correct |
34 |
Correct |
552 ms |
19552 KB |
Output is correct |
35 |
Correct |
570 ms |
19592 KB |
Output is correct |
36 |
Correct |
499 ms |
24380 KB |
Output is correct |
37 |
Correct |
573 ms |
21088 KB |
Output is correct |
38 |
Correct |
594 ms |
23012 KB |
Output is correct |
39 |
Correct |
568 ms |
21088 KB |
Output is correct |
40 |
Correct |
506 ms |
28372 KB |
Output is correct |
41 |
Correct |
565 ms |
28372 KB |
Output is correct |
42 |
Correct |
503 ms |
27348 KB |
Output is correct |
43 |
Correct |
578 ms |
23136 KB |
Output is correct |
44 |
Correct |
584 ms |
23008 KB |
Output is correct |
45 |
Correct |
621 ms |
28244 KB |
Output is correct |
46 |
Correct |
547 ms |
20704 KB |
Output is correct |
47 |
Correct |
567 ms |
20708 KB |
Output is correct |
48 |
Correct |
439 ms |
17508 KB |
Output is correct |
49 |
Correct |
646 ms |
28144 KB |
Output is correct |
50 |
Correct |
582 ms |
23136 KB |
Output is correct |
51 |
Correct |
643 ms |
28112 KB |
Output is correct |
52 |
Correct |
506 ms |
20572 KB |
Output is correct |
53 |
Correct |
565 ms |
29012 KB |
Output is correct |