Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define ff first
- #define ss second
- #define pb push_back
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- _test
- {
- int n;
- cin>>n;
- vector<array<int, 4>> va(n);
- // b a r l
- for(auto &[b, a, r, l]: va)
- cin>>l>>r>>a>>b;
- unordered_map<int, int> ans;
- sort(va.rbegin(), va.rend());
- multiset<int> farthest;
- multiset<array<int, 2>> closing;
- for(auto [b, a, r, l]: va)
- {
- while(closing.size() && (*closing.rbegin())[0] > b)
- {
- if(farthest.find(((*closing.rbegin())[1])) != farthest.end())
- farthest.erase(farthest.find(((*closing.rbegin())[1])));
- closing.erase(--closing.end());
- }
- ans[b] = max(ans[b], b);
- if(farthest.size())
- ans[b] = max(ans[b], ans[*farthest.rbegin()]);
- closing.insert({l, b});
- farthest.insert(b);
- }
- int q;
- cin>>q;
- vector<int> x(q);
- for(auto &e: x)
- cin>>e;
- vector<array<int, 2>> que;
- for(int i=0; i<q; i++)
- que.pb({x[i], i});
- sort(que.begin(), que.end());
- vector<int> vals(q);
- vector<array<int, 4>> va2;
- //l r a b
- for(auto [b, a, r, l]: va)
- va2.pb({l, r, a, b});
- sort(va2.rbegin(), va2.rend());
- closing.clear();
- farthest.clear();
- for(auto [e, ind]: que)
- {
- while(closing.size() && (*closing.begin())[0]<e)
- {
- if(farthest.find((*closing.begin())[1]) != farthest.end())
- farthest.erase(farthest.find((*closing.begin())[1]));
- closing.erase(--closing.end());
- }
- while(va2.size() && va2.back()[0]<=e)
- {
- if(va2.back()[1] <= e)
- {
- va2.pop_back();
- continue;
- }
- farthest.insert(va2.back()[3]);
- closing.insert({va2.back()[1], va2.back()[3]});
- va2.pop_back();
- }
- vals[ind] = e;
- if(farthest.size())
- vals[ind] = max(vals[ind], ans[*farthest.rbegin()]);
- }
- for(auto e: vals)
- cout<<e<<" ";
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment