Guest User

Untitled

a guest
Jun 27th, 2017
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  typedef unsigned long long ull;
  5.  typedef pair < int, int > pii;
  6.  const int inf = 0x3f3f3f3f;
  7.  const double eps = 1e-8;
  8.  const int mod = 1000000007;
  9.  const double pi = acos(-1.0);
  10.  inline void gn(long long & x) {
  11.      int sg = 1;
  12.      char c;
  13.      while (((c = getchar()) < '0' || c > '9') && c != '-');
  14.      c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  15.      while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  16.      x *= sg;
  17.  }
  18.  inline void gn(int & x) {
  19.      long long t;
  20.      gn(t);
  21.      x = t;
  22.  }
  23.  inline void gn(unsigned long long & x) {
  24.      long long t;
  25.      gn(t);
  26.      x = t;
  27.  }
  28.  ll gcd(ll a, ll b) {
  29.      return a ? gcd(b % a, a) : b;
  30.  }
  31.  ll powmod(ll a, ll x, ll mod) {
  32.      ll t = 1 ll;
  33.      while (x) {
  34.          if (x & 1) t = t * a % mod;
  35.          a = a * a % mod;
  36.          x >>= 1;
  37.      }
  38.      return t;
  39.  }
  40.  const int maxn = 6e5 + 5;
  41.  int a[maxn];
  42.  stack < int > st;
  43.  char op[40];
  44.  int n;
  45.  int main() {
  46.      gn(n);
  47.      int nowdo = 0;
  48.      int ans = 0;
  49.      for (int i = 1; i <= 2 * n; ++i) {
  50.          scanf("%s", op);
  51.          if (op[0] == 'a') {
  52.              int x;
  53.              gn(x);
  54.              st.push(x);
  55.              a[x] = 1;
  56.          } else {
  57.              nowdo++;
  58.              if (a[nowdo] == 2 && st.empty()) continue;
  59.              else if (nowdo == st.top()) st.pop();
  60.              else {
  61.                  ++ans;
  62.                  while (!st.empty()) {
  63.                      int x = st.top();
  64.                      a[x] = 2;
  65.                      st.pop();
  66.                  }
  67.              }
  68.          }
  69.      }
  70.      cout << ans << endl;
  71.      return 0;
  72.  }
Add Comment
Please, Sign In to add comment