///breaker
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx")
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define fi first
#define se second
#define ii pair<int,int>
#define mp make_pair
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define bit(x,i) ((x>>i)&1)
#define lc (id<<1)
#define rc ((id<<1)^1)
const int maxn=1e5+7;
const int sz=350;
struct fenwick
{
vector <int> fen;
int n;
fenwick(int _n=1e5)
{
n=_n;
fen.assign(n+5,0);
}
void add(int pos)
{
for(;pos>0;pos-=pos&-pos) fen[pos]++;
return;
}
int get(int pos)
{
if (!pos) return 0;
int ans=0;
for(;pos<=n;pos+=pos&-pos) ans+=fen[pos];
return ans;
}
}t[sz+3];
struct Data
{
int x,y,z,id;
};
int n,q;
Data a[maxn];
Data qu[maxn];
int ans[maxn];
ordered_set s[maxn];
vector<int>vx;
vector<int>vy;
int pos(int x,vector<int>&v)
{
return lower_bound(v.begin(),v.end(),x)-v.begin()+1;
}
bool cmp(Data &a,Data &b)
{
return a.z>b.z;
}
void sol(void){
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i].x>>a[i].y;
vx.push_back(a[i].x);
vy.push_back(a[i].y);
a[i].z=a[i].x+a[i].y;
}
for(int i=1;i<=q;i++){
cin>>qu[i].x>>qu[i].y>>qu[i].z;
qu[i].id=i;
}
sort(vx.begin(),vx.end());
sort(vy.begin(),vy.end());
vx.erase(unique(vx.begin(),vx.end()),vx.end());
vy.erase(unique(vy.begin(),vy.end()),vy.end());
sort(a+1,a+n+1,cmp);
sort(qu+1,qu+q+1,cmp);
int l=1;
for(int i=1;i<=n;i++){
int pos1=pos(a[i].x,vx);
int pos2=pos(a[i].y,vy);
t[(pos1-1)/sz].add(pos2);
s[pos1].insert({pos2,i});
if(i<n&&a[i].z==a[i+1].z)continue;
while(l<=q&&(i==n||qu[l].z>a[i+1].z)){
if(qu[l].z>a[i].z){
l++;
continue;
}
pos1=pos(qu[l].x,vx);
pos2=pos(qu[l].y,vy);
int tmp=0;
for(int block=(pos1-1)/sz+1; block<=(vx.size()-1)/sz; block++)tmp+=t[block].get(pos2);
for(int els=pos1; els<=min(n,((pos1-1)/sz+1)*sz); els++)tmp+=s[els].size()-s[els].order_of_key({pos2,0});
ans[qu[l].id]=tmp;
l++;
}
}
for(int i=1;i<=q;i++){
cout<<ans[i]<<"\n";
}
return;
}
signed main(void)
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
while(t--){
sol();
}
// you should actually read the stuff at the bottom
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Compilation message
examination.cpp: In function 'void sol()':
examination.cpp:98:47: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for(int block=(pos1-1)/sz+1; block<=(vx.size()-1)/sz; block++)tmp+=t[block].get(pos2);
| ~~~~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
148308 KB |
Output is correct |
2 |
Correct |
57 ms |
148308 KB |
Output is correct |
3 |
Correct |
62 ms |
148396 KB |
Output is correct |
4 |
Correct |
64 ms |
148408 KB |
Output is correct |
5 |
Correct |
66 ms |
148308 KB |
Output is correct |
6 |
Correct |
65 ms |
148324 KB |
Output is correct |
7 |
Correct |
88 ms |
148820 KB |
Output is correct |
8 |
Correct |
73 ms |
148904 KB |
Output is correct |
9 |
Correct |
69 ms |
148920 KB |
Output is correct |
10 |
Correct |
67 ms |
148820 KB |
Output is correct |
11 |
Correct |
69 ms |
148816 KB |
Output is correct |
12 |
Correct |
69 ms |
148816 KB |
Output is correct |
13 |
Correct |
69 ms |
148820 KB |
Output is correct |
14 |
Correct |
67 ms |
148816 KB |
Output is correct |
15 |
Correct |
67 ms |
148920 KB |
Output is correct |
16 |
Correct |
65 ms |
148820 KB |
Output is correct |
17 |
Correct |
72 ms |
148820 KB |
Output is correct |
18 |
Correct |
68 ms |
148816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1255 ms |
161908 KB |
Output is correct |
2 |
Correct |
1126 ms |
162104 KB |
Output is correct |
3 |
Correct |
1130 ms |
161956 KB |
Output is correct |
4 |
Correct |
740 ms |
161220 KB |
Output is correct |
5 |
Correct |
320 ms |
161396 KB |
Output is correct |
6 |
Correct |
252 ms |
160632 KB |
Output is correct |
7 |
Correct |
1457 ms |
162028 KB |
Output is correct |
8 |
Correct |
711 ms |
161908 KB |
Output is correct |
9 |
Correct |
878 ms |
161828 KB |
Output is correct |
10 |
Correct |
230 ms |
161140 KB |
Output is correct |
11 |
Correct |
636 ms |
161000 KB |
Output is correct |
12 |
Correct |
206 ms |
160100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1255 ms |
161908 KB |
Output is correct |
2 |
Correct |
1126 ms |
162104 KB |
Output is correct |
3 |
Correct |
1130 ms |
161956 KB |
Output is correct |
4 |
Correct |
740 ms |
161220 KB |
Output is correct |
5 |
Correct |
320 ms |
161396 KB |
Output is correct |
6 |
Correct |
252 ms |
160632 KB |
Output is correct |
7 |
Correct |
1457 ms |
162028 KB |
Output is correct |
8 |
Correct |
711 ms |
161908 KB |
Output is correct |
9 |
Correct |
878 ms |
161828 KB |
Output is correct |
10 |
Correct |
230 ms |
161140 KB |
Output is correct |
11 |
Correct |
636 ms |
161000 KB |
Output is correct |
12 |
Correct |
206 ms |
160100 KB |
Output is correct |
13 |
Correct |
957 ms |
162420 KB |
Output is correct |
14 |
Correct |
1086 ms |
162496 KB |
Output is correct |
15 |
Correct |
1157 ms |
161936 KB |
Output is correct |
16 |
Correct |
635 ms |
161652 KB |
Output is correct |
17 |
Correct |
299 ms |
161592 KB |
Output is correct |
18 |
Correct |
246 ms |
160628 KB |
Output is correct |
19 |
Correct |
952 ms |
162420 KB |
Output is correct |
20 |
Correct |
1037 ms |
162472 KB |
Output is correct |
21 |
Correct |
867 ms |
162424 KB |
Output is correct |
22 |
Correct |
223 ms |
161180 KB |
Output is correct |
23 |
Correct |
632 ms |
161016 KB |
Output is correct |
24 |
Correct |
197 ms |
160116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
148308 KB |
Output is correct |
2 |
Correct |
57 ms |
148308 KB |
Output is correct |
3 |
Correct |
62 ms |
148396 KB |
Output is correct |
4 |
Correct |
64 ms |
148408 KB |
Output is correct |
5 |
Correct |
66 ms |
148308 KB |
Output is correct |
6 |
Correct |
65 ms |
148324 KB |
Output is correct |
7 |
Correct |
88 ms |
148820 KB |
Output is correct |
8 |
Correct |
73 ms |
148904 KB |
Output is correct |
9 |
Correct |
69 ms |
148920 KB |
Output is correct |
10 |
Correct |
67 ms |
148820 KB |
Output is correct |
11 |
Correct |
69 ms |
148816 KB |
Output is correct |
12 |
Correct |
69 ms |
148816 KB |
Output is correct |
13 |
Correct |
69 ms |
148820 KB |
Output is correct |
14 |
Correct |
67 ms |
148816 KB |
Output is correct |
15 |
Correct |
67 ms |
148920 KB |
Output is correct |
16 |
Correct |
65 ms |
148820 KB |
Output is correct |
17 |
Correct |
72 ms |
148820 KB |
Output is correct |
18 |
Correct |
68 ms |
148816 KB |
Output is correct |
19 |
Correct |
1255 ms |
161908 KB |
Output is correct |
20 |
Correct |
1126 ms |
162104 KB |
Output is correct |
21 |
Correct |
1130 ms |
161956 KB |
Output is correct |
22 |
Correct |
740 ms |
161220 KB |
Output is correct |
23 |
Correct |
320 ms |
161396 KB |
Output is correct |
24 |
Correct |
252 ms |
160632 KB |
Output is correct |
25 |
Correct |
1457 ms |
162028 KB |
Output is correct |
26 |
Correct |
711 ms |
161908 KB |
Output is correct |
27 |
Correct |
878 ms |
161828 KB |
Output is correct |
28 |
Correct |
230 ms |
161140 KB |
Output is correct |
29 |
Correct |
636 ms |
161000 KB |
Output is correct |
30 |
Correct |
206 ms |
160100 KB |
Output is correct |
31 |
Correct |
957 ms |
162420 KB |
Output is correct |
32 |
Correct |
1086 ms |
162496 KB |
Output is correct |
33 |
Correct |
1157 ms |
161936 KB |
Output is correct |
34 |
Correct |
635 ms |
161652 KB |
Output is correct |
35 |
Correct |
299 ms |
161592 KB |
Output is correct |
36 |
Correct |
246 ms |
160628 KB |
Output is correct |
37 |
Correct |
952 ms |
162420 KB |
Output is correct |
38 |
Correct |
1037 ms |
162472 KB |
Output is correct |
39 |
Correct |
867 ms |
162424 KB |
Output is correct |
40 |
Correct |
223 ms |
161180 KB |
Output is correct |
41 |
Correct |
632 ms |
161016 KB |
Output is correct |
42 |
Correct |
197 ms |
160116 KB |
Output is correct |
43 |
Correct |
1396 ms |
164456 KB |
Output is correct |
44 |
Correct |
1442 ms |
164472 KB |
Output is correct |
45 |
Correct |
1501 ms |
164388 KB |
Output is correct |
46 |
Correct |
833 ms |
162868 KB |
Output is correct |
47 |
Correct |
296 ms |
162936 KB |
Output is correct |
48 |
Correct |
169 ms |
160376 KB |
Output is correct |
49 |
Correct |
2146 ms |
164148 KB |
Output is correct |
50 |
Correct |
884 ms |
164412 KB |
Output is correct |
51 |
Correct |
1191 ms |
164232 KB |
Output is correct |
52 |
Correct |
261 ms |
162736 KB |
Output is correct |
53 |
Correct |
905 ms |
161860 KB |
Output is correct |