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;
const int MX=1e6+5;
int N,Q;
int S[MX],T[MX], X[MX], Y[MX], Z[MX], ans[MX];
struct fenwick {
int t[MX];
void upd(int pos, int val) {
for(int i=pos;i<MX;i+=i&-i) t[i]+=val;
}
int que(int pos) {
int res=0;
for(int i=pos;i>0;i-=i&-i) res+=t[i];
return res;
}
} ft, tt;
map<int,int> id;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin>>N>>Q;
for(int i=1;i<=N;i++) cin>>S[i]>>T[i];
for(int i=1;i<=Q;i++) {
cin>>X[i]>>Y[i]>>Z[i];
Z[i]=max(Z[i],X[i]+Y[i]);
}
map<int,int> id;
for(int i=1;i<=N;i++) {
id[S[i]]=0;
id[T[i]]=0;
id[S[i]+T[i]]=0;
}
for(int i=1;i<=Q;i++) {
id[X[i]]=0;
id[Y[i]]=0;
id[Z[i]]=0;
}
int z=1;
for(auto &[x,y]:id) y=z++;
vector<array<int,4>> v;
for(int i=1;i<=N;i++)
v.push_back({S[i]+T[i],S[i],T[i],MX});
for(int i=1;i<=Q;i++)
v.push_back({Z[i],X[i],Y[i],i});
sort(v.rbegin(),v.rend());
int cnt=0;
for(auto [s,x,y,i]:v) {
if(i==MX) {
cnt+=1;
ft.upd(id[x],1);
tt.upd(id[y],1);
} else {
ans[i]=cnt-ft.que(id[x]-1)-tt.que(id[y]-1);
}
}
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... |