#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);
//cout<<"update: "<<pos1<<" "<<pos2<<" "<<a[i].x<<" "<<a[i].y<<" "<<a[i].z<<endl;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
157652 KB |
Output is correct |
2 |
Correct |
69 ms |
157648 KB |
Output is correct |
3 |
Correct |
73 ms |
157688 KB |
Output is correct |
4 |
Correct |
72 ms |
157736 KB |
Output is correct |
5 |
Correct |
72 ms |
157672 KB |
Output is correct |
6 |
Correct |
70 ms |
157736 KB |
Output is correct |
7 |
Correct |
79 ms |
158188 KB |
Output is correct |
8 |
Correct |
90 ms |
158192 KB |
Output is correct |
9 |
Correct |
88 ms |
158172 KB |
Output is correct |
10 |
Correct |
74 ms |
158100 KB |
Output is correct |
11 |
Correct |
79 ms |
158120 KB |
Output is correct |
12 |
Correct |
76 ms |
158132 KB |
Output is correct |
13 |
Correct |
83 ms |
158200 KB |
Output is correct |
14 |
Correct |
81 ms |
158248 KB |
Output is correct |
15 |
Correct |
88 ms |
158168 KB |
Output is correct |
16 |
Correct |
85 ms |
158140 KB |
Output is correct |
17 |
Correct |
76 ms |
158156 KB |
Output is correct |
18 |
Correct |
76 ms |
158064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1625 ms |
169248 KB |
Output is correct |
2 |
Correct |
1679 ms |
169340 KB |
Output is correct |
3 |
Correct |
1514 ms |
169300 KB |
Output is correct |
4 |
Correct |
1020 ms |
169400 KB |
Output is correct |
5 |
Correct |
465 ms |
169408 KB |
Output is correct |
6 |
Correct |
314 ms |
168968 KB |
Output is correct |
7 |
Correct |
1943 ms |
169304 KB |
Output is correct |
8 |
Correct |
1370 ms |
169360 KB |
Output is correct |
9 |
Correct |
1574 ms |
169288 KB |
Output is correct |
10 |
Correct |
256 ms |
169152 KB |
Output is correct |
11 |
Correct |
863 ms |
169180 KB |
Output is correct |
12 |
Correct |
259 ms |
168648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1625 ms |
169248 KB |
Output is correct |
2 |
Correct |
1679 ms |
169340 KB |
Output is correct |
3 |
Correct |
1514 ms |
169300 KB |
Output is correct |
4 |
Correct |
1020 ms |
169400 KB |
Output is correct |
5 |
Correct |
465 ms |
169408 KB |
Output is correct |
6 |
Correct |
314 ms |
168968 KB |
Output is correct |
7 |
Correct |
1943 ms |
169304 KB |
Output is correct |
8 |
Correct |
1370 ms |
169360 KB |
Output is correct |
9 |
Correct |
1574 ms |
169288 KB |
Output is correct |
10 |
Correct |
256 ms |
169152 KB |
Output is correct |
11 |
Correct |
863 ms |
169180 KB |
Output is correct |
12 |
Correct |
259 ms |
168648 KB |
Output is correct |
13 |
Correct |
1328 ms |
169072 KB |
Output is correct |
14 |
Correct |
1487 ms |
169124 KB |
Output is correct |
15 |
Correct |
1475 ms |
169096 KB |
Output is correct |
16 |
Correct |
870 ms |
169064 KB |
Output is correct |
17 |
Correct |
361 ms |
169124 KB |
Output is correct |
18 |
Correct |
396 ms |
168980 KB |
Output is correct |
19 |
Correct |
1361 ms |
169048 KB |
Output is correct |
20 |
Correct |
1391 ms |
169004 KB |
Output is correct |
21 |
Correct |
1424 ms |
169004 KB |
Output is correct |
22 |
Correct |
258 ms |
169000 KB |
Output is correct |
23 |
Correct |
885 ms |
168960 KB |
Output is correct |
24 |
Correct |
301 ms |
168736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
157652 KB |
Output is correct |
2 |
Correct |
69 ms |
157648 KB |
Output is correct |
3 |
Correct |
73 ms |
157688 KB |
Output is correct |
4 |
Correct |
72 ms |
157736 KB |
Output is correct |
5 |
Correct |
72 ms |
157672 KB |
Output is correct |
6 |
Correct |
70 ms |
157736 KB |
Output is correct |
7 |
Correct |
79 ms |
158188 KB |
Output is correct |
8 |
Correct |
90 ms |
158192 KB |
Output is correct |
9 |
Correct |
88 ms |
158172 KB |
Output is correct |
10 |
Correct |
74 ms |
158100 KB |
Output is correct |
11 |
Correct |
79 ms |
158120 KB |
Output is correct |
12 |
Correct |
76 ms |
158132 KB |
Output is correct |
13 |
Correct |
83 ms |
158200 KB |
Output is correct |
14 |
Correct |
81 ms |
158248 KB |
Output is correct |
15 |
Correct |
88 ms |
158168 KB |
Output is correct |
16 |
Correct |
85 ms |
158140 KB |
Output is correct |
17 |
Correct |
76 ms |
158156 KB |
Output is correct |
18 |
Correct |
76 ms |
158064 KB |
Output is correct |
19 |
Correct |
1625 ms |
169248 KB |
Output is correct |
20 |
Correct |
1679 ms |
169340 KB |
Output is correct |
21 |
Correct |
1514 ms |
169300 KB |
Output is correct |
22 |
Correct |
1020 ms |
169400 KB |
Output is correct |
23 |
Correct |
465 ms |
169408 KB |
Output is correct |
24 |
Correct |
314 ms |
168968 KB |
Output is correct |
25 |
Correct |
1943 ms |
169304 KB |
Output is correct |
26 |
Correct |
1370 ms |
169360 KB |
Output is correct |
27 |
Correct |
1574 ms |
169288 KB |
Output is correct |
28 |
Correct |
256 ms |
169152 KB |
Output is correct |
29 |
Correct |
863 ms |
169180 KB |
Output is correct |
30 |
Correct |
259 ms |
168648 KB |
Output is correct |
31 |
Correct |
1328 ms |
169072 KB |
Output is correct |
32 |
Correct |
1487 ms |
169124 KB |
Output is correct |
33 |
Correct |
1475 ms |
169096 KB |
Output is correct |
34 |
Correct |
870 ms |
169064 KB |
Output is correct |
35 |
Correct |
361 ms |
169124 KB |
Output is correct |
36 |
Correct |
396 ms |
168980 KB |
Output is correct |
37 |
Correct |
1361 ms |
169048 KB |
Output is correct |
38 |
Correct |
1391 ms |
169004 KB |
Output is correct |
39 |
Correct |
1424 ms |
169004 KB |
Output is correct |
40 |
Correct |
258 ms |
169000 KB |
Output is correct |
41 |
Correct |
885 ms |
168960 KB |
Output is correct |
42 |
Correct |
301 ms |
168736 KB |
Output is correct |
43 |
Correct |
1562 ms |
169032 KB |
Output is correct |
44 |
Correct |
1611 ms |
173796 KB |
Output is correct |
45 |
Correct |
1606 ms |
173808 KB |
Output is correct |
46 |
Correct |
1475 ms |
172332 KB |
Output is correct |
47 |
Correct |
414 ms |
172132 KB |
Output is correct |
48 |
Correct |
207 ms |
169792 KB |
Output is correct |
49 |
Correct |
2302 ms |
173676 KB |
Output is correct |
50 |
Correct |
1494 ms |
173800 KB |
Output is correct |
51 |
Correct |
2764 ms |
173576 KB |
Output is correct |
52 |
Correct |
336 ms |
171996 KB |
Output is correct |
53 |
Correct |
1582 ms |
171372 KB |
Output is correct |