Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int n,X;
- cin >> n >> X;
- ordered_set<pair<int,int>> st; /// sort by priority
- set<pair<int,int>> notImportant;
- queue<pair<int,int>> q;
- for(int i = 0; i < n; i++){
- char ch;
- cin >> ch;
- if(ch == '+'){
- int t,p;
- cin >> t >> p;
- int k = st.order_of_key(mp(p,-1));
- q.push(mp(p,t));
- st.insert(mp(p,t));
- if(st.size() >= 2 && k >= 2){
- // cerr << "NotImportant! " << t << "\n";
- notImportant.insert(mp(p,t));
- int pm0 = st.begin()->first, pm1 = (++st.begin())->first;
- if((p - pm0) * (p - pm1) > X){
- while(!notImportant.empty()){
- int p0 = notImportant.begin()->first, t0 = notImportant.begin()->second;
- st.erase(st.find(mp(p0,t0)));
- notImportant.erase(notImportant.begin());
- }
- }
- }
- } else {
- while(!q.empty() && st.find(q.front()) == st.end())
- q.pop();
- st.erase(q.front());
- notImportant.erase(q.front());
- while(!notImportant.empty()){
- int p0 = (--notImportant.end())->first, t0 = (--notImportant.end())->second;
- if(st.order_of_key(mp(p0,-1)) >= 2)
- break;
- notImportant.erase(--notImportant.end());
- }
- cout << q.front().second << "\n";
- q.pop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement