Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- int main()
- {
- ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0);
- int n; cin >> n; n *= 2;
- set<int> ord;
- vector<int> v;
- int cnt = 0;
- while(n--)
- {
- string req; int a; cin >> req;
- if(req == "add")
- {
- int a; cin >> a;
- v.push_back(a);
- }
- else
- {
- if(!v.empty())
- {
- if(v.back() == a)
- v.pop_back();
- else
- {
- while(!v.empty())
- {
- ord.insert(v.back());
- v.pop_back();
- }
- cnt++;
- ord.erase(ord.begin());
- }
- }
- else ord.erase(ord.begin());
- }
- }
- cout << cnt;
- //3
- //add 1
- //remove
- //add 2
- //add 3
- //remove
- //remove
- }
Advertisement
Add Comment
Please, Sign In to add comment