This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
struct st {
int x, y, z, i;
};
vector<st> v;
struct fenwick {
int t[400010];
void upd(int n, int x) {
for(;n<=4e5;n+=n&-n)
t[n]+=x;
}
int q(int n) {
int x = 0;
for(;n;n-=n&-n)
x+=t[n];
return x;
}
int Q(int x) {
return q(4e5)-q(x-1);
}
} A,B;
int ans[100100];
map<int,int> mp;
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
for(int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
mp[a], mp[b];
v.push_back({a,b,a+b,0});
}
for(int i = 1; i <= q; i++) {
int x,y,z;
cin >> x >> y>> z;
mp[x],mp[y];
v.push_back({x,y,max(z,x+y),i});
}
sort(v.begin(),v.end(),[](st a, st b) {
return (a.z-b.z?a.z>b.z:a.i<b.i);
});
int cnt = 0;
for(auto &i: mp)
i.second=++cnt;
cnt=0;
for(auto i: v)
if(i.i)
ans[i.i]=A.Q(mp[i.x])+B.Q(mp[i.y])-cnt;
else
A.upd(mp[i.x],1),B.upd(mp[i.y],1),cnt++;
for(int i = 1; i <= q; i++)
cout << ans[i] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |