Submission #978082

#TimeUsernameProblemLanguageResultExecution timeMemory
978082happy_nodeExamination (JOI19_examination)C++17
0 / 100
3065 ms19264 KiB
#include <bits/stdc++.h> using namespace std; const int MX=4e5+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; 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]); } 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,id]:v) { if(id==MX) { cnt+=1; ft.upd(x,1); tt.upd(y,1); } else { ans[id]=cnt-ft.que(x-1)-tt.que(y-1); } } for(int i=1;i<=Q;i++) { cout<<ans[i]<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...