Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef pair < int, int > pii;
- const int inf = 0x3f3f3f3f;
- const double eps = 1e-8;
- const int mod = 1000000007;
- const double pi = acos(-1.0);
- inline void gn(long long & x) {
- int sg = 1;
- char c;
- while (((c = getchar()) < '0' || c > '9') && c != '-');
- c == '-' ? (sg = -1, x = 0) : (x = c - '0');
- while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
- x *= sg;
- }
- inline void gn(int & x) {
- long long t;
- gn(t);
- x = t;
- }
- inline void gn(unsigned long long & x) {
- long long t;
- gn(t);
- x = t;
- }
- ll gcd(ll a, ll b) {
- return a ? gcd(b % a, a) : b;
- }
- ll powmod(ll a, ll x, ll mod) {
- ll t = 1 ll;
- while (x) {
- if (x & 1) t = t * a % mod;
- a = a * a % mod;
- x >>= 1;
- }
- return t;
- }
- const int maxn = 6e5 + 5;
- int a[maxn];
- stack < int > st;
- char op[40];
- int n;
- int main() {
- gn(n);
- int nowdo = 0;
- int ans = 0;
- for (int i = 1; i <= 2 * n; ++i) {
- scanf("%s", op);
- if (op[0] == 'a') {
- int x;
- gn(x);
- st.push(x);
- a[x] = 1;
- } else {
- nowdo++;
- if (a[nowdo] == 2 && st.empty()) continue;
- else if (nowdo == st.top()) st.pop();
- else {
- ++ans;
- while (!st.empty()) {
- int x = st.top();
- a[x] = 2;
- st.pop();
- }
- }
- }
- }
- cout << ans << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment