#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx")
#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 forw(i,a,b) for(ll i=a;i<=b;i++)
#define forb(i,a,b) for(ll i=a;i>=b;i--)
#define fi first
#define se second
#define pb push_back
#define pu push
#define all(a) a.begin(),a.end()
#define getbit(mask,i) ((mask>>(i))&1)
#define minimize(a,b) (a)=min((a),(b))
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll maxN=2e5+5;
const ll mod=1e9+9;
const ll oo=1e18+1;
const int tx[4]={-1,1,0,0};
const int ty[4]={0,0,-1,1};
const int len=350;
struct fenwick
{
vector <int> fen;
int n;
fenwick(int _n=1e5)
{
n=_n;
fen.assign(n+5,0);
}
void update(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;
}
}fen[len+3];
struct dataa
{
int x,y,z,id;
};
dataa a[maxN],query[maxN];
ordered_set save[maxN];
int n,q,ans[maxN];
vector <int> pend_x,pend_y;
bool cmp(dataa &a, dataa &b)
{
return a.z>b.z;
}
void solve()
{
cin>>n>>q;
forw(i,1,n)
{
cin>>a[i].x>>a[i].y;
a[i].z=a[i].x+a[i].y;
pend_x.pb(a[i].x);
pend_y.pb(a[i].y);
}
sort(a+1,a+1+n,cmp);
sort(all(pend_x)); pend_x.resize(unique(all(pend_x))-pend_x.begin());
sort(all(pend_y)); pend_y.resize(unique(all(pend_y))-pend_y.begin());
forw(i,1,q)
{
cin>>query[i].x>>query[i].y>>query[i].z;
query[i].id=i;
}
sort(query+1,query+1+q,cmp);
int idx=1;
forw(i,1,n)
{
int pos1=lower_bound(all(pend_x),a[i].x)-pend_x.begin()+1;
int pos2=lower_bound(all(pend_y),a[i].y)-pend_y.begin()+1;
// update ele
save[pos1].insert({pos2,i});
// update block
pos1=(pos1-1)/len;
fen[pos1].update(pos2);
if (i<n && a[i].z==a[i+1].z) continue;
while (idx<=q && (i==n || a[i+1].z<query[idx].z))
{
if (a[i].z<query[idx].z)
{
idx++;
continue;
}
int cnt=0;
pos1=lower_bound(all(pend_x),query[idx].x)-pend_x.begin()+1;
pos2=lower_bound(all(pend_y),query[idx].y)-pend_y.begin()+1;
int L=(pos1-1)/len;
int R=(pend_x.size()-1)/len;
// get block
forw(block,L+1,R)
cnt+=fen[block].get(pos2);
// get ele
forw(ele,pos1,(L+1)*len)
cnt+=save[ele].size()-save[ele].order_of_key({pos2,0});
ans[query[idx].id]=cnt;
idx++;
}
}
forw(i,1,q) cout<<ans[i]<<"\n";
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("bruh.inp","r",stdin);
//freopen("bruh.out","w",stdout);
int t=1; //cin>>t;
while (t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
157784 KB |
Output is correct |
2 |
Correct |
71 ms |
157824 KB |
Output is correct |
3 |
Correct |
70 ms |
157776 KB |
Output is correct |
4 |
Correct |
69 ms |
157780 KB |
Output is correct |
5 |
Correct |
73 ms |
157684 KB |
Output is correct |
6 |
Correct |
70 ms |
157776 KB |
Output is correct |
7 |
Correct |
73 ms |
158032 KB |
Output is correct |
8 |
Correct |
74 ms |
158120 KB |
Output is correct |
9 |
Correct |
78 ms |
158032 KB |
Output is correct |
10 |
Correct |
83 ms |
158096 KB |
Output is correct |
11 |
Correct |
78 ms |
158100 KB |
Output is correct |
12 |
Correct |
72 ms |
158036 KB |
Output is correct |
13 |
Correct |
81 ms |
158032 KB |
Output is correct |
14 |
Correct |
77 ms |
158140 KB |
Output is correct |
15 |
Correct |
75 ms |
158032 KB |
Output is correct |
16 |
Correct |
78 ms |
158156 KB |
Output is correct |
17 |
Correct |
89 ms |
158156 KB |
Output is correct |
18 |
Correct |
77 ms |
158036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1118 ms |
168872 KB |
Output is correct |
2 |
Correct |
1122 ms |
169056 KB |
Output is correct |
3 |
Correct |
1164 ms |
168920 KB |
Output is correct |
4 |
Correct |
755 ms |
168904 KB |
Output is correct |
5 |
Correct |
330 ms |
168904 KB |
Output is correct |
6 |
Correct |
248 ms |
168900 KB |
Output is correct |
7 |
Correct |
1455 ms |
168952 KB |
Output is correct |
8 |
Correct |
696 ms |
168908 KB |
Output is correct |
9 |
Correct |
910 ms |
168972 KB |
Output is correct |
10 |
Correct |
217 ms |
168896 KB |
Output is correct |
11 |
Correct |
598 ms |
168892 KB |
Output is correct |
12 |
Correct |
208 ms |
168588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1118 ms |
168872 KB |
Output is correct |
2 |
Correct |
1122 ms |
169056 KB |
Output is correct |
3 |
Correct |
1164 ms |
168920 KB |
Output is correct |
4 |
Correct |
755 ms |
168904 KB |
Output is correct |
5 |
Correct |
330 ms |
168904 KB |
Output is correct |
6 |
Correct |
248 ms |
168900 KB |
Output is correct |
7 |
Correct |
1455 ms |
168952 KB |
Output is correct |
8 |
Correct |
696 ms |
168908 KB |
Output is correct |
9 |
Correct |
910 ms |
168972 KB |
Output is correct |
10 |
Correct |
217 ms |
168896 KB |
Output is correct |
11 |
Correct |
598 ms |
168892 KB |
Output is correct |
12 |
Correct |
208 ms |
168588 KB |
Output is correct |
13 |
Correct |
978 ms |
168932 KB |
Output is correct |
14 |
Correct |
1107 ms |
168848 KB |
Output is correct |
15 |
Correct |
1103 ms |
168900 KB |
Output is correct |
16 |
Correct |
605 ms |
168900 KB |
Output is correct |
17 |
Correct |
299 ms |
168900 KB |
Output is correct |
18 |
Correct |
256 ms |
168924 KB |
Output is correct |
19 |
Correct |
945 ms |
169012 KB |
Output is correct |
20 |
Correct |
1022 ms |
168952 KB |
Output is correct |
21 |
Correct |
814 ms |
168904 KB |
Output is correct |
22 |
Correct |
215 ms |
168648 KB |
Output is correct |
23 |
Correct |
589 ms |
168644 KB |
Output is correct |
24 |
Correct |
213 ms |
168648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
157784 KB |
Output is correct |
2 |
Correct |
71 ms |
157824 KB |
Output is correct |
3 |
Correct |
70 ms |
157776 KB |
Output is correct |
4 |
Correct |
69 ms |
157780 KB |
Output is correct |
5 |
Correct |
73 ms |
157684 KB |
Output is correct |
6 |
Correct |
70 ms |
157776 KB |
Output is correct |
7 |
Correct |
73 ms |
158032 KB |
Output is correct |
8 |
Correct |
74 ms |
158120 KB |
Output is correct |
9 |
Correct |
78 ms |
158032 KB |
Output is correct |
10 |
Correct |
83 ms |
158096 KB |
Output is correct |
11 |
Correct |
78 ms |
158100 KB |
Output is correct |
12 |
Correct |
72 ms |
158036 KB |
Output is correct |
13 |
Correct |
81 ms |
158032 KB |
Output is correct |
14 |
Correct |
77 ms |
158140 KB |
Output is correct |
15 |
Correct |
75 ms |
158032 KB |
Output is correct |
16 |
Correct |
78 ms |
158156 KB |
Output is correct |
17 |
Correct |
89 ms |
158156 KB |
Output is correct |
18 |
Correct |
77 ms |
158036 KB |
Output is correct |
19 |
Correct |
1118 ms |
168872 KB |
Output is correct |
20 |
Correct |
1122 ms |
169056 KB |
Output is correct |
21 |
Correct |
1164 ms |
168920 KB |
Output is correct |
22 |
Correct |
755 ms |
168904 KB |
Output is correct |
23 |
Correct |
330 ms |
168904 KB |
Output is correct |
24 |
Correct |
248 ms |
168900 KB |
Output is correct |
25 |
Correct |
1455 ms |
168952 KB |
Output is correct |
26 |
Correct |
696 ms |
168908 KB |
Output is correct |
27 |
Correct |
910 ms |
168972 KB |
Output is correct |
28 |
Correct |
217 ms |
168896 KB |
Output is correct |
29 |
Correct |
598 ms |
168892 KB |
Output is correct |
30 |
Correct |
208 ms |
168588 KB |
Output is correct |
31 |
Correct |
978 ms |
168932 KB |
Output is correct |
32 |
Correct |
1107 ms |
168848 KB |
Output is correct |
33 |
Correct |
1103 ms |
168900 KB |
Output is correct |
34 |
Correct |
605 ms |
168900 KB |
Output is correct |
35 |
Correct |
299 ms |
168900 KB |
Output is correct |
36 |
Correct |
256 ms |
168924 KB |
Output is correct |
37 |
Correct |
945 ms |
169012 KB |
Output is correct |
38 |
Correct |
1022 ms |
168952 KB |
Output is correct |
39 |
Correct |
814 ms |
168904 KB |
Output is correct |
40 |
Correct |
215 ms |
168648 KB |
Output is correct |
41 |
Correct |
589 ms |
168644 KB |
Output is correct |
42 |
Correct |
213 ms |
168648 KB |
Output is correct |
43 |
Correct |
1349 ms |
168812 KB |
Output is correct |
44 |
Correct |
1364 ms |
173772 KB |
Output is correct |
45 |
Correct |
1402 ms |
174064 KB |
Output is correct |
46 |
Correct |
834 ms |
172144 KB |
Output is correct |
47 |
Correct |
305 ms |
172132 KB |
Output is correct |
48 |
Correct |
184 ms |
169928 KB |
Output is correct |
49 |
Correct |
2192 ms |
173624 KB |
Output is correct |
50 |
Correct |
845 ms |
173804 KB |
Output is correct |
51 |
Correct |
1256 ms |
173512 KB |
Output is correct |
52 |
Correct |
278 ms |
171976 KB |
Output is correct |
53 |
Correct |
904 ms |
171212 KB |
Output is correct |