Advertisement
welleyth

B. ИОИП 2 2022

Mar 13th, 2022
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. int n,X;
  2.     cin >> n >> X;
  3.  
  4.     ordered_set<pair<int,int>> st; /// sort by priority
  5.     set<pair<int,int>> notImportant;
  6.     queue<pair<int,int>> q;
  7.  
  8.     for(int i = 0; i < n; i++){
  9.         char ch;
  10.         cin >> ch;
  11.         if(ch == '+'){
  12.             int t,p;
  13.             cin >> t >> p;
  14.             int k = st.order_of_key(mp(p,-1));
  15.             q.push(mp(p,t));
  16.             st.insert(mp(p,t));
  17.             if(st.size() >= 2 && k >= 2){
  18. //                cerr << "NotImportant! " << t << "\n";
  19.                 notImportant.insert(mp(p,t));
  20.                 int pm0 = st.begin()->first, pm1 = (++st.begin())->first;
  21.                 if((p - pm0) * (p - pm1) > X){
  22.                     while(!notImportant.empty()){
  23.                         int p0 = notImportant.begin()->first, t0 = notImportant.begin()->second;
  24.                         st.erase(st.find(mp(p0,t0)));
  25.                         notImportant.erase(notImportant.begin());
  26.                     }
  27.                 }
  28.             }
  29.         } else {
  30.             while(!q.empty() && st.find(q.front()) == st.end())
  31.                 q.pop();
  32.             st.erase(q.front());
  33.             notImportant.erase(q.front());
  34.             while(!notImportant.empty()){
  35.                 int p0 = (--notImportant.end())->first, t0 = (--notImportant.end())->second;
  36.                 if(st.order_of_key(mp(p0,-1)) >= 2)
  37.                     break;
  38.                 notImportant.erase(--notImportant.end());
  39.             }
  40.             cout << q.front().second << "\n";
  41.             q.pop();
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement