#include <bits/stdc++.h>
using namespace std;
using nagai = long long;
#define sz(x) int((x).size())
int act=0;
struct fen{
vector<int>v;
vector<int>t;
void add1(int x,int y){
for(;x<t.size();x+=x&-x)
t[x]+=y;
}
int get(int x){
if(act<2)return 0;
int ans=0;
for(;x;x-=x&-x)
ans+=t[x];
return ans;
}
void add(int x,int y){
if(act<2)
return v.push_back(x);
x=lower_bound(v.begin(),v.end(),x)-v.begin();
add1(x+1,y);
}
int get(int l,int r){
l=lower_bound(v.begin(),v.end(),l)-v.begin();
r=lower_bound(v.begin(),v.end(),r)-v.begin();
return get(r)-get(l);
}
};
const int N=100100;
const int oo=2.1e9;
struct FEN{
fen kek[N];
vector<int>v;
void add1(int x,int y,int z){
for(;x<N;x+=x&-x)
kek[x].add(y,z);
}
int get(int x,int y1,int y2){
if(act<2)return 0;
int ans=0;
for(;x;x-=x&-x)
ans+=kek[x].get(y1,y2);
return ans;
}
void add(int x,int y,int z){
if(act==0)
return v.push_back(x);
x=lower_bound(v.begin(),v.end(),x)-v.begin();
add1(x+1,y,z);
}
int get(int x1,int x2,int y1,int y2){
x1=lower_bound(v.begin(),v.end(),x1)-v.begin();
x2=lower_bound(v.begin(),v.end(),x2)-v.begin();
return get(x2,y1,y2)-get(x1,y1,y2);
}
void init(){
if(act==0){
sort(v.begin(),v.end());
}
else{
for(int i=0;i<N;++i){
kek[i].v.push_back(oo+5);
kek[i].v.push_back(oo+5);
sort(kek[i].v.begin(),kek[i].v.end());
kek[i].t.resize(kek[i].v.size()+1);
}
}
++act;
}
} F;
int n,q;
int xs[N],ys[N];
int as[N],bs[N],cs[N];
struct ev{
int x,y1,y2,z1,z2,id;
bool operator <(ev o)const {
if(x!=o.x)
return x>o.x;
return id<o.id;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>q;
for(int i=0;i<n;++i){
cin>>xs[i]>>ys[i];
}
for(int i=0;i<q;++i){
cin>>as[i]>>bs[i]>>cs[i];
}
vector<int>ans(q);
for(int i=0;i<3;++i){
vector<ev>evs;
for(int i=0;i<n;++i)
evs.push_back({xs[i],ys[i],ys[i],xs[i]+ys[i],xs[i]+ys[i],-1});
for(int i=0;i<q;++i){
evs.push_back({as[i],bs[i],oo,cs[i],oo,i});
}
sort(evs.begin(),evs.end());
for(auto e:evs){
if(e.id==-1){
F.add(e.y1,e.z1,1);
continue;
}
ans[e.id]=F.get(e.y1,e.y2,e.z1,e.z2);
}
F.init();
}
for(int i=0;i<q;++i)
cout<<ans[i]<<'\n';
return 0;
}
Compilation message
examination.cpp: In member function 'void fen::add1(int, int)':
examination.cpp:13:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(;x<t.size();x+=x&-x)
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
11384 KB |
Output is correct |
2 |
Correct |
32 ms |
11384 KB |
Output is correct |
3 |
Correct |
33 ms |
11352 KB |
Output is correct |
4 |
Correct |
33 ms |
11392 KB |
Output is correct |
5 |
Correct |
31 ms |
11328 KB |
Output is correct |
6 |
Correct |
31 ms |
11264 KB |
Output is correct |
7 |
Correct |
46 ms |
12316 KB |
Output is correct |
8 |
Correct |
47 ms |
12296 KB |
Output is correct |
9 |
Correct |
47 ms |
12316 KB |
Output is correct |
10 |
Correct |
44 ms |
12288 KB |
Output is correct |
11 |
Correct |
47 ms |
12252 KB |
Output is correct |
12 |
Correct |
41 ms |
12200 KB |
Output is correct |
13 |
Correct |
47 ms |
12284 KB |
Output is correct |
14 |
Correct |
47 ms |
12264 KB |
Output is correct |
15 |
Correct |
46 ms |
12260 KB |
Output is correct |
16 |
Correct |
45 ms |
12204 KB |
Output is correct |
17 |
Correct |
46 ms |
12444 KB |
Output is correct |
18 |
Correct |
41 ms |
12328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
660 ms |
32800 KB |
Output is correct |
2 |
Correct |
657 ms |
36096 KB |
Output is correct |
3 |
Correct |
655 ms |
35472 KB |
Output is correct |
4 |
Correct |
396 ms |
35868 KB |
Output is correct |
5 |
Correct |
610 ms |
35260 KB |
Output is correct |
6 |
Correct |
275 ms |
35340 KB |
Output is correct |
7 |
Correct |
610 ms |
35348 KB |
Output is correct |
8 |
Correct |
587 ms |
35832 KB |
Output is correct |
9 |
Correct |
552 ms |
35708 KB |
Output is correct |
10 |
Correct |
598 ms |
34540 KB |
Output is correct |
11 |
Correct |
356 ms |
41340 KB |
Output is correct |
12 |
Correct |
319 ms |
40408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
660 ms |
32800 KB |
Output is correct |
2 |
Correct |
657 ms |
36096 KB |
Output is correct |
3 |
Correct |
655 ms |
35472 KB |
Output is correct |
4 |
Correct |
396 ms |
35868 KB |
Output is correct |
5 |
Correct |
610 ms |
35260 KB |
Output is correct |
6 |
Correct |
275 ms |
35340 KB |
Output is correct |
7 |
Correct |
610 ms |
35348 KB |
Output is correct |
8 |
Correct |
587 ms |
35832 KB |
Output is correct |
9 |
Correct |
552 ms |
35708 KB |
Output is correct |
10 |
Correct |
598 ms |
34540 KB |
Output is correct |
11 |
Correct |
356 ms |
41340 KB |
Output is correct |
12 |
Correct |
319 ms |
40408 KB |
Output is correct |
13 |
Correct |
755 ms |
35848 KB |
Output is correct |
14 |
Correct |
678 ms |
35964 KB |
Output is correct |
15 |
Correct |
633 ms |
35452 KB |
Output is correct |
16 |
Correct |
463 ms |
36352 KB |
Output is correct |
17 |
Correct |
710 ms |
35764 KB |
Output is correct |
18 |
Correct |
304 ms |
35560 KB |
Output is correct |
19 |
Correct |
927 ms |
36708 KB |
Output is correct |
20 |
Correct |
762 ms |
36748 KB |
Output is correct |
21 |
Correct |
712 ms |
36092 KB |
Output is correct |
22 |
Correct |
651 ms |
35196 KB |
Output is correct |
23 |
Correct |
502 ms |
41472 KB |
Output is correct |
24 |
Correct |
326 ms |
40408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
11384 KB |
Output is correct |
2 |
Correct |
32 ms |
11384 KB |
Output is correct |
3 |
Correct |
33 ms |
11352 KB |
Output is correct |
4 |
Correct |
33 ms |
11392 KB |
Output is correct |
5 |
Correct |
31 ms |
11328 KB |
Output is correct |
6 |
Correct |
31 ms |
11264 KB |
Output is correct |
7 |
Correct |
46 ms |
12316 KB |
Output is correct |
8 |
Correct |
47 ms |
12296 KB |
Output is correct |
9 |
Correct |
47 ms |
12316 KB |
Output is correct |
10 |
Correct |
44 ms |
12288 KB |
Output is correct |
11 |
Correct |
47 ms |
12252 KB |
Output is correct |
12 |
Correct |
41 ms |
12200 KB |
Output is correct |
13 |
Correct |
47 ms |
12284 KB |
Output is correct |
14 |
Correct |
47 ms |
12264 KB |
Output is correct |
15 |
Correct |
46 ms |
12260 KB |
Output is correct |
16 |
Correct |
45 ms |
12204 KB |
Output is correct |
17 |
Correct |
46 ms |
12444 KB |
Output is correct |
18 |
Correct |
41 ms |
12328 KB |
Output is correct |
19 |
Correct |
660 ms |
32800 KB |
Output is correct |
20 |
Correct |
657 ms |
36096 KB |
Output is correct |
21 |
Correct |
655 ms |
35472 KB |
Output is correct |
22 |
Correct |
396 ms |
35868 KB |
Output is correct |
23 |
Correct |
610 ms |
35260 KB |
Output is correct |
24 |
Correct |
275 ms |
35340 KB |
Output is correct |
25 |
Correct |
610 ms |
35348 KB |
Output is correct |
26 |
Correct |
587 ms |
35832 KB |
Output is correct |
27 |
Correct |
552 ms |
35708 KB |
Output is correct |
28 |
Correct |
598 ms |
34540 KB |
Output is correct |
29 |
Correct |
356 ms |
41340 KB |
Output is correct |
30 |
Correct |
319 ms |
40408 KB |
Output is correct |
31 |
Correct |
755 ms |
35848 KB |
Output is correct |
32 |
Correct |
678 ms |
35964 KB |
Output is correct |
33 |
Correct |
633 ms |
35452 KB |
Output is correct |
34 |
Correct |
463 ms |
36352 KB |
Output is correct |
35 |
Correct |
710 ms |
35764 KB |
Output is correct |
36 |
Correct |
304 ms |
35560 KB |
Output is correct |
37 |
Correct |
927 ms |
36708 KB |
Output is correct |
38 |
Correct |
762 ms |
36748 KB |
Output is correct |
39 |
Correct |
712 ms |
36092 KB |
Output is correct |
40 |
Correct |
651 ms |
35196 KB |
Output is correct |
41 |
Correct |
502 ms |
41472 KB |
Output is correct |
42 |
Correct |
326 ms |
40408 KB |
Output is correct |
43 |
Correct |
762 ms |
38248 KB |
Output is correct |
44 |
Correct |
742 ms |
38232 KB |
Output is correct |
45 |
Correct |
736 ms |
38276 KB |
Output is correct |
46 |
Correct |
471 ms |
37244 KB |
Output is correct |
47 |
Correct |
677 ms |
36884 KB |
Output is correct |
48 |
Correct |
316 ms |
35296 KB |
Output is correct |
49 |
Correct |
683 ms |
38144 KB |
Output is correct |
50 |
Correct |
666 ms |
38196 KB |
Output is correct |
51 |
Correct |
609 ms |
38232 KB |
Output is correct |
52 |
Correct |
627 ms |
36476 KB |
Output is correct |
53 |
Correct |
475 ms |
42160 KB |
Output is correct |