Sanitator

Untitled

Jan 7th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0);
  9.  
  10.     int n; cin >> n; n *= 2;
  11.  
  12.     set<int> ord;
  13.     vector<int> v;
  14.     int cnt = 0;
  15.  
  16.     while(n--)
  17.     {
  18.         string req; int a; cin >> req;
  19.         if(req == "add")
  20.         {
  21.             int a; cin >> a;
  22.             v.push_back(a);
  23.         }
  24.         else
  25.         {
  26.             if(!v.empty())
  27.             {
  28.                 if(v.back() == a)
  29.                     v.pop_back();
  30.                 else
  31.                 {
  32.                     while(!v.empty())
  33.                     {
  34.                         ord.insert(v.back());
  35.                         v.pop_back();
  36.                     }
  37.                     cnt++;
  38.                     ord.erase(ord.begin());
  39.                 }
  40.             }
  41.             else ord.erase(ord.begin());
  42.         }
  43.     }
  44.     cout << cnt;
  45.    
  46. //3
  47. //add 1
  48. //remove
  49. //add 2
  50. //add 3
  51. //remove
  52. //remove
  53. }
Advertisement
Add Comment
Please, Sign In to add comment