Submission #998388

#TimeUsernameProblemLanguageResultExecution timeMemory
998388vjudge1Examination (JOI19_examination)C++17
100 / 100
899 ms56248 KiB
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() #define ll long long #define endl '\n' const int N = 1e6 + 6, LOG = 27, MOD = 1e9 + 7; const ll INF = 1e18; void solver(); signed main() { cin.tie(0)->sync_with_stdio(0); int t = 1; // cin>>t; while (t--) solver(); } int n,q; ll res[N],max_val = 1; struct op{ ll x = 0,y = 0,z = 0; int idx = 0,val = 0; op(ll x,ll y,ll z,int i,int v):x(x),y(y),z(z),idx(i),val(v){} bool operator < (const op &b) const{ op a = *this; if(a.x == b.x) return a.val > b.val; return (a.x == b.x ? (a.y == b.y ? a.z < b.z : a.y < b.y) : a.x > b.x); } }; vector<op>v; void compress(){ map<ll,int>mp; for(int i = 0;i < n + q;++i){ mp[v[i].x] = true; mp[v[i].y] = true; mp[v[i].z] = true; } for(auto i : mp) mp[i.first] = max_val++; for(int i = 0; i < n + q; i++){ v[i].x = mp[v[i].x]; v[i].y = mp[v[i].y]; v[i].z = mp[v[i].z]; } } namespace bit{ ll tr[N]; int lowbit(int i){return i&(-i);} void update(int i,ll val){ for(;i <= max_val;i += lowbit(i)) tr[i] += val; } ll get(int l,int r){ auto sum=[&](int i){ ll res = 0; for(;i > 0;i-=lowbit(i)) res += tr[i]; return res; }; return sum(r) - sum(l - 1); } }; void calc_cont(int l,int m,int r){ int a = l,b = m + 1; vector<op>tmp; vector<pair<int,int>>record; while(a <= m && b <= r){ if(v[a].y >= v[b].y){ bit::update(v[a].z,v[a].val); record.emplace_back(v[a].z,v[a].val); tmp.push_back(v[a]); ++a; }else{ res[v[b].idx] += bit::get(v[b].z,max_val); tmp.push_back(v[b]); ++b; } } while(a <= m){ tmp.push_back(v[a]); ++a; } while(b <= r){ res[v[b].idx] += bit::get(v[b].z,max_val); tmp.push_back(v[b]); ++b; } for(int i = l;i <= r;++i) v[i] = tmp[i - l]; for(auto &[pos,val] : record) bit::update(pos,-val); } void cdq(int l,int r){ if(l == r) return; int m = (r+l) >> 1; cdq(l,m); cdq(m+1,r); calc_cont(l,m,r); } void solver() { cin>>n>>q; for(int i = 0;i < n;++i){ ll x,y; cin>>x>>y; v.push_back({x,y,x + y,i,1}); } for(int i = n;i < n + q;++i){ ll x,y,z; cin>>x>>y>>z; v.push_back({x,y,z,i,0}); } compress(); sort(v.begin(),v.end()); cdq(0,n + q - 1); for(int i = n;i < n + q;++i) cout<<res[i]<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...