Submission #1014139

#TimeUsernameProblemLanguageResultExecution timeMemory
1014139pccNew Home (APIO18_new_home)C++17
10 / 100
1890 ms797616 KiB
#include <bits/stdc++.h> using namespace std; #define _all(T) T.begin(),T.end() #define pii pair<int,int> #define fs first #define sc second const int mxn = 1e6; const int inf = 1e9; const int lim = 1e8+10; struct SEG{ #define mid ((l+r)>>1) #define ls now*2+1 #define rs now*2+2 int seg[mxn*4]; vector<vector<pii>> op; SEG(){ fill(seg,seg+mxn*4,-inf); } void modify(int now,int l,int r,int s,int e,int v){ if(!now)op.push_back({}); op.back().push_back(pii(now,seg[now])); if(l>=s&&e>=r){ seg[now] = max(seg[now],v); return; } if(mid>=s)modify(ls,l,mid,s,e,v); if(mid<e)modify(rs,mid+1,r,s,e,v); return; } void undo(){ while(!op.back().empty()){ auto [p,v] = op.back().back(); op.back().pop_back(); seg[p] = v; } op.pop_back(); return; } int getval(int now,int l,int r,int p){ if(l == r)return seg[now]; if(mid>=p)return max(seg[now],getval(ls,l,mid,p)); else return max(seg[now],getval(rs,mid+1,r,p)); } #undef mid #undef ls #undef rs }; SEG seg1,seg2; int N,K,Q; set<int> st[mxn]; vector<int> all; vector<pii> req; array<int,4> shop[mxn]; int ans[mxn]; vector<pii> tseg[mxn*4]; int main(){ cin>>N>>K>>Q; for(int i = 1;i<=N;i++){ cin>>shop[i][0]>>shop[i][1]>>shop[i][2]>>shop[i][3];//x,t,a,b all.push_back(shop[i][0]); } for(int i = 0;i<Q;i++){ int l,y; cin>>l>>y; all.push_back(l); req.push_back(pii(l,y)); } all.push_back(-inf);all.push_back(inf); sort(_all(all));all.resize(unique(_all(all))-all.begin()); for(int i = 1;i<=K;i++){ st[i].insert(0); st[i].insert(all.size()-1); } for(int i = 1;i<=N;i++){ shop[i][0] = lower_bound(_all(all),shop[i][0])-all.begin(); st[shop[i][1]].insert(shop[i][0]); } for(int i = 1;i<=K;i++){ for(auto it = ++st[i].begin();it != st[i].end();it++){ int l = *prev(it),r = *it; int mid = all[l]+(all[r]-all[l])/2; auto pos = upper_bound(_all(all),mid)-all.begin(); seg1.modify(0,0,all.size(),l,pos-1,-all[l]); seg2.modify(0,0,all.size(),pos,r,all[r]); } } for(auto [pos,_] : req){ pos = lower_bound(_all(all),pos)-all.begin(); int ans = max(all[pos]+seg1.getval(0,0,all.size(),pos),seg2.getval(0,0,all.size(),pos)-all[pos]); cout<<(ans>=lim?-1:ans)<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...