#include<bits/stdc++.h>
using namespace std;
int n,q;
struct point{
int i,x,y,z;
point(int id=0,int a=0,int b=0,int c=0){
i=id,x=a,y=b,z=c;
}
bool operator<(const point &t){
return x==t.x?y>t.y:x<t.x;
}
};
vector<point>v;
int ans[600005];
point temp[600005];
struct fenwick{
int info[600005];
void upd(int id,int val){
for(int i=id;i<=600000;i+=i&-i)info[i]+=val;
}
int fsum(int id){
int ans=0;
for(int i=id;i>0;i-=i&-i){
ans+=info[i];
}
return ans;
}
}fw;
void solve(int st,int en){
if(st==en)return;
int m=(st+en)/2;
solve(st,m);
solve(m+1,en);
//cerr<<st<<" "<<en<<"\n";
int i=st,j=m+1;
int id=st;
//cerr<<"in solve work\n";
while(i<=m||j<=en){
if(j>en||(i<=m&&v[i].y>v[j].y)){
temp[id++]=v[i];
if(v[i].i<=n)fw.upd(v[i].z,1);
i++;
}else{
temp[id++]=v[j];
ans[v[j].i]+=fw.fsum(600000)-fw.fsum(v[j].z);
j++;
}
}
//cerr<<"in solve work\n";
for(int i=st;i<=m;i++)if(v[i].i<=n)fw.upd(v[i].z,-1);
for(int i=st;i<=en;i++)v[i]=temp[i];
}
vector<int>val;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++){
int a,b;
cin>>a>>b;
v.push_back(point(i,a,b,a+b));
val.push_back(a);
val.push_back(b);
val.push_back(a+b);
}
for(int i=1;i<=q;i++){
int a,b,c;
cin>>a>>b>>c;
v.push_back(point(n+i,a,b,c));
val.push_back(a);
val.push_back(b);
val.push_back(c);
}
sort(val.begin(),val.end());
//for(auto x:val)cerr<<x<<" ";
//cerr<<"\n";
for(auto &x:v){
//cerr<<lower_bound(val.begin(),val.end(),x.x)-val.begin()<<"+"<<1<<"\n";
x.x=lower_bound(val.begin(),val.end(),x.x)-val.begin()+1;
x.y=lower_bound(val.begin(),val.end(),x.y)-val.begin()+1;
x.z=lower_bound(val.begin(),val.end(),x.z)-val.begin()+1;
if(x.i>n)x.x--,x.y--,x.z--;
}
//cerr<<"work\n";
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
//for(auto x:v)cerr<<x.i<<" "<<x.x<<" "<<x.y<<" "<<x.z<<"\n";
//cerr<<"work\n";
solve(0,v.size()-1);
//cerr<<"work\n";
for(int i=n+1;i<=n+q;i++){
cout<<ans[i]<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
3 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
10584 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
9 ms |
11100 KB |
Output is correct |
8 |
Correct |
9 ms |
11100 KB |
Output is correct |
9 |
Correct |
9 ms |
11100 KB |
Output is correct |
10 |
Correct |
9 ms |
11100 KB |
Output is correct |
11 |
Correct |
8 ms |
11100 KB |
Output is correct |
12 |
Correct |
6 ms |
11100 KB |
Output is correct |
13 |
Correct |
9 ms |
11208 KB |
Output is correct |
14 |
Correct |
9 ms |
11076 KB |
Output is correct |
15 |
Correct |
9 ms |
11100 KB |
Output is correct |
16 |
Correct |
7 ms |
11100 KB |
Output is correct |
17 |
Correct |
8 ms |
13144 KB |
Output is correct |
18 |
Correct |
7 ms |
11096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
273 ms |
20716 KB |
Output is correct |
2 |
Correct |
257 ms |
20124 KB |
Output is correct |
3 |
Correct |
257 ms |
18852 KB |
Output is correct |
4 |
Correct |
199 ms |
20156 KB |
Output is correct |
5 |
Correct |
192 ms |
20916 KB |
Output is correct |
6 |
Correct |
116 ms |
20660 KB |
Output is correct |
7 |
Correct |
236 ms |
21672 KB |
Output is correct |
8 |
Correct |
240 ms |
22448 KB |
Output is correct |
9 |
Correct |
232 ms |
22744 KB |
Output is correct |
10 |
Correct |
183 ms |
19808 KB |
Output is correct |
11 |
Correct |
179 ms |
21316 KB |
Output is correct |
12 |
Correct |
168 ms |
20656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
273 ms |
20716 KB |
Output is correct |
2 |
Correct |
257 ms |
20124 KB |
Output is correct |
3 |
Correct |
257 ms |
18852 KB |
Output is correct |
4 |
Correct |
199 ms |
20156 KB |
Output is correct |
5 |
Correct |
192 ms |
20916 KB |
Output is correct |
6 |
Correct |
116 ms |
20660 KB |
Output is correct |
7 |
Correct |
236 ms |
21672 KB |
Output is correct |
8 |
Correct |
240 ms |
22448 KB |
Output is correct |
9 |
Correct |
232 ms |
22744 KB |
Output is correct |
10 |
Correct |
183 ms |
19808 KB |
Output is correct |
11 |
Correct |
179 ms |
21316 KB |
Output is correct |
12 |
Correct |
168 ms |
20656 KB |
Output is correct |
13 |
Correct |
285 ms |
22436 KB |
Output is correct |
14 |
Correct |
302 ms |
23712 KB |
Output is correct |
15 |
Correct |
255 ms |
23052 KB |
Output is correct |
16 |
Correct |
234 ms |
20900 KB |
Output is correct |
17 |
Correct |
230 ms |
21716 KB |
Output is correct |
18 |
Correct |
154 ms |
20668 KB |
Output is correct |
19 |
Correct |
283 ms |
23136 KB |
Output is correct |
20 |
Correct |
285 ms |
23192 KB |
Output is correct |
21 |
Correct |
279 ms |
23460 KB |
Output is correct |
22 |
Correct |
175 ms |
21168 KB |
Output is correct |
23 |
Correct |
178 ms |
19436 KB |
Output is correct |
24 |
Correct |
162 ms |
20148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
3 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
10584 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
9 ms |
11100 KB |
Output is correct |
8 |
Correct |
9 ms |
11100 KB |
Output is correct |
9 |
Correct |
9 ms |
11100 KB |
Output is correct |
10 |
Correct |
9 ms |
11100 KB |
Output is correct |
11 |
Correct |
8 ms |
11100 KB |
Output is correct |
12 |
Correct |
6 ms |
11100 KB |
Output is correct |
13 |
Correct |
9 ms |
11208 KB |
Output is correct |
14 |
Correct |
9 ms |
11076 KB |
Output is correct |
15 |
Correct |
9 ms |
11100 KB |
Output is correct |
16 |
Correct |
7 ms |
11100 KB |
Output is correct |
17 |
Correct |
8 ms |
13144 KB |
Output is correct |
18 |
Correct |
7 ms |
11096 KB |
Output is correct |
19 |
Correct |
273 ms |
20716 KB |
Output is correct |
20 |
Correct |
257 ms |
20124 KB |
Output is correct |
21 |
Correct |
257 ms |
18852 KB |
Output is correct |
22 |
Correct |
199 ms |
20156 KB |
Output is correct |
23 |
Correct |
192 ms |
20916 KB |
Output is correct |
24 |
Correct |
116 ms |
20660 KB |
Output is correct |
25 |
Correct |
236 ms |
21672 KB |
Output is correct |
26 |
Correct |
240 ms |
22448 KB |
Output is correct |
27 |
Correct |
232 ms |
22744 KB |
Output is correct |
28 |
Correct |
183 ms |
19808 KB |
Output is correct |
29 |
Correct |
179 ms |
21316 KB |
Output is correct |
30 |
Correct |
168 ms |
20656 KB |
Output is correct |
31 |
Correct |
285 ms |
22436 KB |
Output is correct |
32 |
Correct |
302 ms |
23712 KB |
Output is correct |
33 |
Correct |
255 ms |
23052 KB |
Output is correct |
34 |
Correct |
234 ms |
20900 KB |
Output is correct |
35 |
Correct |
230 ms |
21716 KB |
Output is correct |
36 |
Correct |
154 ms |
20668 KB |
Output is correct |
37 |
Correct |
283 ms |
23136 KB |
Output is correct |
38 |
Correct |
285 ms |
23192 KB |
Output is correct |
39 |
Correct |
279 ms |
23460 KB |
Output is correct |
40 |
Correct |
175 ms |
21168 KB |
Output is correct |
41 |
Correct |
178 ms |
19436 KB |
Output is correct |
42 |
Correct |
162 ms |
20148 KB |
Output is correct |
43 |
Correct |
296 ms |
24004 KB |
Output is correct |
44 |
Correct |
319 ms |
25720 KB |
Output is correct |
45 |
Correct |
302 ms |
25880 KB |
Output is correct |
46 |
Correct |
244 ms |
21784 KB |
Output is correct |
47 |
Correct |
235 ms |
22936 KB |
Output is correct |
48 |
Correct |
138 ms |
19388 KB |
Output is correct |
49 |
Correct |
286 ms |
25656 KB |
Output is correct |
50 |
Correct |
306 ms |
24124 KB |
Output is correct |
51 |
Correct |
278 ms |
23600 KB |
Output is correct |
52 |
Correct |
227 ms |
22180 KB |
Output is correct |
53 |
Correct |
186 ms |
20444 KB |
Output is correct |