//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
struct node{
int x,y,z,id;
bool operator<(const node &a)const{
if(x!=a.x) return x<a.x;
if(y!=a.y) return y<a.y;
if(z!=a.z) return z<a.z;
return a.id<id;
}
};
vector<node>vec;
const int mxn=2e5+5;
int ans[mxn];
int bit[mxn];
void update(int pos,int val){
for(;pos<mxn;pos+=(pos&-pos)){
bit[pos]+=val;
}
}
int query(int pos){
int ans=0;
for(;pos;pos-=(pos&-pos)){
ans+=bit[pos];
}
return ans;
}
bool comp(node a,node b){
return a.y<b.y;
}
void go(int l,int r){
if(l==r){
return;
}
int mid=(l+r)/2;
go(l,mid);
go(mid+1,r);
int R=r;
for(int L=mid;L>=l;L--){
while(R>mid and vec[R].y>=vec[L].y){
if(vec[R].id==-1){
update(vec[R].z,1);
}
R--;
}
if(vec[L].id!=-1){
ans[vec[L].id]+=query(mxn-1)-query(vec[L].z-1);
}
}
R++;
while(R<=r){
if(vec[R].id==-1){
update(vec[R].z,-1);
}
R++;
}
sort(vec.begin()+l,vec.begin()+r+1,comp);
}
int main() {_
int n,m;
cin>>n>>m;
vec.resize(n+m);
for(int i=0;i<n;i++){
cin>>vec[i].x>>vec[i].y;
vec[i].z=vec[i].x+vec[i].y;
vec[i].id=-1;
}
for(int i=n;i<n+m;i++){
cin>>vec[i].x>>vec[i].y>>vec[i].z;
vec[i].id=i-n;
}
vector<int> zs;
zs.push_back(-1);
for(int i=0;i<n+m;i++){
zs.push_back(vec[i].z);
}
sort(all(zs));
zs.resize(unique(all(zs))-zs.begin());
for(int i=0;i<n+m;i++){
vec[i].z=lower_bound(all(zs),vec[i].z)-zs.begin();
}
sort(all(vec));
go(0,n+m-1);
for(int i=0;i<m;i++){
cout<<ans[i]<<'\n';
}
return 0;
}
//maybe its multiset not set
//yeeorz
//laborz
Compilation message
examination.cpp: In function 'void setIO(std::string)':
examination.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
728 KB |
Output is correct |
8 |
Correct |
8 ms |
604 KB |
Output is correct |
9 |
Correct |
7 ms |
604 KB |
Output is correct |
10 |
Correct |
6 ms |
604 KB |
Output is correct |
11 |
Correct |
6 ms |
732 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
7 ms |
600 KB |
Output is correct |
14 |
Correct |
7 ms |
604 KB |
Output is correct |
15 |
Correct |
7 ms |
796 KB |
Output is correct |
16 |
Correct |
7 ms |
604 KB |
Output is correct |
17 |
Correct |
5 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
322 ms |
8408 KB |
Output is correct |
2 |
Correct |
316 ms |
8064 KB |
Output is correct |
3 |
Correct |
324 ms |
8308 KB |
Output is correct |
4 |
Correct |
200 ms |
7420 KB |
Output is correct |
5 |
Correct |
246 ms |
7428 KB |
Output is correct |
6 |
Correct |
141 ms |
6460 KB |
Output is correct |
7 |
Correct |
304 ms |
8112 KB |
Output is correct |
8 |
Correct |
300 ms |
8140 KB |
Output is correct |
9 |
Correct |
295 ms |
8004 KB |
Output is correct |
10 |
Correct |
196 ms |
7112 KB |
Output is correct |
11 |
Correct |
171 ms |
7172 KB |
Output is correct |
12 |
Correct |
132 ms |
5920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
322 ms |
8408 KB |
Output is correct |
2 |
Correct |
316 ms |
8064 KB |
Output is correct |
3 |
Correct |
324 ms |
8308 KB |
Output is correct |
4 |
Correct |
200 ms |
7420 KB |
Output is correct |
5 |
Correct |
246 ms |
7428 KB |
Output is correct |
6 |
Correct |
141 ms |
6460 KB |
Output is correct |
7 |
Correct |
304 ms |
8112 KB |
Output is correct |
8 |
Correct |
300 ms |
8140 KB |
Output is correct |
9 |
Correct |
295 ms |
8004 KB |
Output is correct |
10 |
Correct |
196 ms |
7112 KB |
Output is correct |
11 |
Correct |
171 ms |
7172 KB |
Output is correct |
12 |
Correct |
132 ms |
5920 KB |
Output is correct |
13 |
Correct |
355 ms |
8724 KB |
Output is correct |
14 |
Correct |
344 ms |
8656 KB |
Output is correct |
15 |
Correct |
322 ms |
8168 KB |
Output is correct |
16 |
Correct |
232 ms |
7888 KB |
Output is correct |
17 |
Correct |
283 ms |
7884 KB |
Output is correct |
18 |
Correct |
149 ms |
6352 KB |
Output is correct |
19 |
Correct |
349 ms |
8736 KB |
Output is correct |
20 |
Correct |
347 ms |
8800 KB |
Output is correct |
21 |
Correct |
344 ms |
8704 KB |
Output is correct |
22 |
Correct |
203 ms |
7296 KB |
Output is correct |
23 |
Correct |
171 ms |
7168 KB |
Output is correct |
24 |
Correct |
130 ms |
6096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
728 KB |
Output is correct |
8 |
Correct |
8 ms |
604 KB |
Output is correct |
9 |
Correct |
7 ms |
604 KB |
Output is correct |
10 |
Correct |
6 ms |
604 KB |
Output is correct |
11 |
Correct |
6 ms |
732 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
7 ms |
600 KB |
Output is correct |
14 |
Correct |
7 ms |
604 KB |
Output is correct |
15 |
Correct |
7 ms |
796 KB |
Output is correct |
16 |
Correct |
7 ms |
604 KB |
Output is correct |
17 |
Correct |
5 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
604 KB |
Output is correct |
19 |
Correct |
322 ms |
8408 KB |
Output is correct |
20 |
Correct |
316 ms |
8064 KB |
Output is correct |
21 |
Correct |
324 ms |
8308 KB |
Output is correct |
22 |
Correct |
200 ms |
7420 KB |
Output is correct |
23 |
Correct |
246 ms |
7428 KB |
Output is correct |
24 |
Correct |
141 ms |
6460 KB |
Output is correct |
25 |
Correct |
304 ms |
8112 KB |
Output is correct |
26 |
Correct |
300 ms |
8140 KB |
Output is correct |
27 |
Correct |
295 ms |
8004 KB |
Output is correct |
28 |
Correct |
196 ms |
7112 KB |
Output is correct |
29 |
Correct |
171 ms |
7172 KB |
Output is correct |
30 |
Correct |
132 ms |
5920 KB |
Output is correct |
31 |
Correct |
355 ms |
8724 KB |
Output is correct |
32 |
Correct |
344 ms |
8656 KB |
Output is correct |
33 |
Correct |
322 ms |
8168 KB |
Output is correct |
34 |
Correct |
232 ms |
7888 KB |
Output is correct |
35 |
Correct |
283 ms |
7884 KB |
Output is correct |
36 |
Correct |
149 ms |
6352 KB |
Output is correct |
37 |
Correct |
349 ms |
8736 KB |
Output is correct |
38 |
Correct |
347 ms |
8800 KB |
Output is correct |
39 |
Correct |
344 ms |
8704 KB |
Output is correct |
40 |
Correct |
203 ms |
7296 KB |
Output is correct |
41 |
Correct |
171 ms |
7168 KB |
Output is correct |
42 |
Correct |
130 ms |
6096 KB |
Output is correct |
43 |
Correct |
364 ms |
10928 KB |
Output is correct |
44 |
Correct |
360 ms |
11300 KB |
Output is correct |
45 |
Correct |
368 ms |
10988 KB |
Output is correct |
46 |
Correct |
238 ms |
9416 KB |
Output is correct |
47 |
Correct |
289 ms |
9332 KB |
Output is correct |
48 |
Correct |
154 ms |
6136 KB |
Output is correct |
49 |
Correct |
347 ms |
10896 KB |
Output is correct |
50 |
Correct |
347 ms |
11008 KB |
Output is correct |
51 |
Correct |
343 ms |
10864 KB |
Output is correct |
52 |
Correct |
228 ms |
9344 KB |
Output is correct |
53 |
Correct |
189 ms |
8144 KB |
Output is correct |