Submission #701459

#TimeUsernameProblemLanguageResultExecution timeMemory
701459Abrar_Al_SamitNew Home (APIO18_new_home)C++17
0 / 100
2020 ms206384 KiB
#include<bits/stdc++.h> using namespace std; const int nax = 3e5 + 10; int l[nax]; int x[nax], t[nax]; int pos[nax]; set<int>live[nax]; int ans[nax]; void PlayGround() { int n, q, k; cin>>n>>k>>q; vector<int>imp; for(int i=0; i<n; ++i) { cin>>x[i]>>t[i]; int a, b; cin>>a>>b; live[t[i]].insert(x[i]); } bool nok = false; for(int i=1; i<=k; ++i) if(live[i].empty()) nok = true; if(nok) { for(int i=0; i<q; ++i) { cout<<"-1\n"; } return; } map<int,vector<int>>query; for(int i=0; i<q; ++i) { int x, y; cin>>x>>y; pos[i] = x; query[x].push_back(i); imp.push_back(x); } map<int, vector<int>>ch; for(int i=1; i<=k; ++i) { for(auto it=live[i].begin(); it!=live[i].end(); ++it) { imp.push_back(*it); ch[*it].push_back(i); if(it==live[i].begin()) continue; int md = (*it + *prev(it)) / 2; ch[md].push_back(i); imp.push_back(md); } } sort(imp.begin(), imp.end()); imp.resize(unique(imp.begin(), imp.end())-imp.begin()); multiset<int>sm, bg; for(int pl : imp) { for(int j : ch[pl]) { if(*live[j].begin()==pl) { if(bg.find(pl)!=bg.end()) bg.erase(bg.find(pl)); sm.insert(pl); } else { sm.erase(sm.find(*live[j].begin())); live[j].erase(live[j].begin()); bg.insert(*live[j].begin()); } } for(int j : query[pl]) { int d1 = 0; if(!sm.empty()) { d1 = pl - *sm.begin(); } int d2 = 0; if(!bg.empty()) { d2 = *prev(bg.end()) - pl; } ans[j] = max(d1, d2); } } for(int i=0; i<q; ++i) { cout<<ans[i]<<'\n'; } // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); PlayGround(); 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...