prithivMLmods/Coder-Stat huggingface dataset:
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {

  int N;
  cin >> N;

  vector<int> p(N);
  int i;
  for (i = 0; i < N; i++)
    cin >> p.at(i);

  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  int ans = 1;

  for (i = 1; i < N; i++) {

    int tmp = p.at(i);

    sort(p.begin(), p.begin() + i + 1);

    if (p.at(0) == tmp)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {

  int N;
  cin >> N;

  vector<int> p(N);
  int i;
  for (i = 0; i < N; i++)
    cin >> p.at(i);

  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  int ans = 1;

  for (i = 1; i < N; i++) {

    int tmp = p.at(i);

    p.at(0) = min(p.at(0), p.at(i));

    if (p.at(0) == tmp)
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int cnt = 0;
  rep(i, n) {
    int min = *min_element(p.begin(), p.begin() + i);
    if (min >= p[i])
      cnt++;
  }
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int cnt = 1;
  int mini = p[0];
  for (int i = 1; i < n; i++) {
    mini = min(mini, p[i - 1]);
    if (mini >= p[i])
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, res, mn;
  int a[100001];
  cin >> n;
  res = 0;
  mn = INT_MAX;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (mn >= a[i]) {
      mn = a[i];
      res++;
    }
  }
  cout << res << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, res, mn;
  int a[200001];
  cin >> n;
  res = 0;
  mn = INT_MAX;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (mn >= a[i]) {
      mn = a[i];
      res++;
    }
  }
  cout << res << endl;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int n, total = 0, minv = 1e5 + 5;
int a[100005];

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] <= minv) {
      minv = a[i];
      total++;
    }
  }
  cout << total << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int n, total = 0, minv = 2138475648;
int a[200005];

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] <= minv) {
      minv = a[i];
      total++;
    }
  }
  cout << total << endl;
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int n, p[20010], count, miiin;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  miiin = p[0];
  for (int i = 0; i < n; i++) {
    if (p[i] == 1) {
      count += 1;
      cout << count << endl;
      return 0;
    }
    if (p[i] <= miiin) {
      count += 1;
      miiin = p[i];
    }
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int n, p[200100], count, miiin;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  miiin = p[0];
  for (int i = 0; i < n; i++) {
    if (p[i] == 1) {
      count += 1;
      cout << count << endl;
      return 0;
    }
    if (p[i] <= miiin) {
      count += 1;
      miiin = p[i];
    }
  }
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  int P[N];
  for (int i = 0; i < N; i++)
    cin >> P[i];

  int ans = 1;
  for (int i = 1; i < N; i++) {
    bool flag = true;
    for (int j = i - 1; j >= 0; j--) {
      if (P[j] < P[i]) {
        flag = false;
        break;
      }
    }
    if (flag)
      ans++;
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  int P[N];
  for (int i = 0; i < N; i++)
    cin >> P[i];

  int M[N], m = INT_MAX;
  for (int i = 0; i < N; i++) {
    m = min(P[i], m);
    M[i] = m;
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (M[i] == P[i]) // P[i]が最小 → P[i] = M[i]
      ans++;
  }

  cout << ans << endl;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define mem(i, a) memset(i, a, sizeof(i))
#define PI acos(-1.0)
#define DMAX 100000 + 5
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000 + 9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(int &f) {
  f = 0;
  ll x = 1;
  char ch = getchar();
  while (ch < 48 || ch > 57) {
    if (ch == '-') {
      x = -1;
    }
    ch = getchar();
  }
  while (ch <= 57 && ch >= 48) {
    f = f * 10 + ch - '0';
    ch = getchar();
  }
  f *= x;
}
int n;
int tr[DMAX];
int a[DMAX];
int ans = 1;
int minn = INF;
int lowbit(int p) { return p & (-p); }
void add(int pos, int val) {
  for (; pos <= n; pos += lowbit(pos)) {
    tr[pos] += val;
  }
}
int query(int pos) {
  int add = 0;
  for (; pos; pos -= lowbit(pos)) {
    add += tr[pos];
  }
  return add;
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
  }
  minn = a[1];
  for (int i = 2; i <= n; i++) {
    if (a[i] < minn) {
      ans++;
      minn = a[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define mem(i, a) memset(i, a, sizeof(i))
#define PI acos(-1.0)
#define DMAX 200000 + 5
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000 + 9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(int &f) {
  f = 0;
  ll x = 1;
  char ch = getchar();
  while (ch < 48 || ch > 57) {
    if (ch == '-') {
      x = -1;
    }
    ch = getchar();
  }
  while (ch <= 57 && ch >= 48) {
    f = f * 10 + ch - '0';
    ch = getchar();
  }
  f *= x;
}
int n;
int tr[DMAX];
int a[DMAX];
int ans = 1;
int minn = INF;
int lowbit(int p) { return p & (-p); }
void add(int pos, int val) {
  for (; pos <= n; pos += lowbit(pos)) {
    tr[pos] += val;
  }
}
int query(int pos) {
  int add = 0;
  for (; pos; pos -= lowbit(pos)) {
    add += tr[pos];
  }
  return add;
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
  }
  minn = a[1];
  for (int i = 2; i <= n; i++) {
    if (a[i] < minn) {
      ans++;
      minn = a[i];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  int p[100000];
  rep(i, n) scanf("%d", &p[i]);

  int mn = n + 1;
  int ans = 0;
  rep(i, n) {
    if (p[i] <= mn)
      ans++;
    mn = min(mn, p[i]);
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  int p[200000];
  rep(i, n) scanf("%d", &p[i]);

  int mn = n + 1;
  int ans = 0;
  rep(i, n) {
    if (p[i] <= mn)
      ans++;
    mn = min(mn, p[i]);
  }
  printf("%d\n", ans);
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  int P[N];
  for (int i = 0; i < N; i++)
    cin >> P[i];
  int j, k, count = 1;
  for (j = 1; j < N; j++) {
    for (k = j - 1; k > -1; k--) {
      if (P[j] > P[k])
        break;
      if (k == 0)
        count++;
    }
  }
  cout << count << endl;

  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  int P[N];
  for (int i = 0; i < N; i++)
    cin >> P[i];
  int j, min = 10000000, count = 0;
  for (j = 0; j < N; j++) {
    if (P[j] < min)
      min = P[j];
    if (min == P[j])
      count++;
  }
  cout << count << endl;

  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Low Elements
 */

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

template <typename T, const int MAX_N> struct BIT {
  int n;
  T bits[MAX_N + 1];
  BIT() {}

  void init(int _n) {
    n = _n;
    // memset(bits, 0, sizeof(bits));
  }

  T sum(int x) {
    T s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, T v) {
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }
};

/* global variables */

BIT<int, MAX_N> bit;

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  bit.init(n);

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int pi;
    scanf("%d", &pi);

    int s = bit.sum(pi);
    if (s == 0)
      cnt++;
    // printf("%d: %d\n", pi, s);

    bit.add(pi, 1);
  }

  printf("%d\n", cnt);
  return 0;
}


Fixed submission:
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Low Elements
 */

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

template <typename T, const int MAX_N> struct BIT {
  int n;
  T bits[MAX_N + 1];
  BIT() {}

  void init(int _n) {
    n = _n;
    // memset(bits, 0, sizeof(bits));
  }

  T sum(int x) {
    T s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, T v) {
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }
};

/* global variables */

BIT<int, MAX_N> bit;

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  bit.init(n);

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int pi;
    scanf("%d", &pi);

    int s = bit.sum(pi);
    if (s == 0)
      cnt++;
    // printf("%d: %d\n", pi, s);

    bit.add(pi, 1);
  }

  printf("%d\n", cnt);
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  int M;
  int S = 0;
  cin >> N;
  vector<int> vec(N);
  for (int X = 0; X < N; X++) {
    cin >> vec.at(N);
  }
  M = vec.at(0);
  for (int X = 1; X < N; X++) {
    if (M >= vec.at(X)) {
      M = vec.at(X);
      S++;
    }
  }
  cout << S + 1 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  int M;
  int S = 0;
  cin >> N;
  vector<int> vec(N);
  for (int X = 0; X < N; X++) {
    cin >> vec.at(X);
  }
  M = vec.at(0);
  for (int X = 1; X < N; X++) {
    if (M >= vec.at(X)) {
      M = vec.at(X);
      S++;
    }
  }
  cout << S + 1 << endl;
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++)
    cin >> vec[i];

  int count = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (vec[j] <= vec[i])
        break;
      if (j == i - 1)
        count++;
    }
  }

  cout << count << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++)
    cin >> vec[i];

  int count = 0;
  int min_num = n + 1;
  for (int i = 0; i < n; i++) {
    if (vec[i] == 1) {
      count++;
      break;
    }

    if (vec[i] < min_num) {
      min_num = vec[i];
      count++;
    }
  }

  cout << count << endl;
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define io_optimized                                                           \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
using namespace std;

int main() {
  io_optimized int n;
  while (cin >> n) {
    int a[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      bool c = 1;
      for (int j = 0; j < i; j++) {
        if (a[j] < a[i]) {
          c = 0;
          break;
        }
      }
      if (c) {
        sum++;
      }
    }
    cout << sum << "\n";
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define io_optimized                                                           \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
using namespace std;

int main() {
  io_optimized int t, n, min;
  while (cin >> t) {
    t--;
    int sum = 1;
    cin >> min;
    while (t--) {
      cin >> n;
      if (n <= min) {
        min = n;
        sum++;
      }
    }
    cout << sum << "\n";
  }

  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b)                                                          \
  for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG2(x, y) cout << #x << ": " << x << " " << #y << ": " << y << endl
#define DEBUG_VEC(v)                                                           \
  cout << #v << ":";                                                           \
  REP(i, v.size()) cout << " " << v[i];                                        \
  cout << endl
#define DEBUG_ARR(v, n)                                                        \
  cout << #v << ":";                                                           \
  REP(i, n) cout << " " << v[i];                                               \
  cout << endl
#define ALL(a) (a).begin(), (a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a) % MOD + MOD) % MOD

int n, s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int p[100010];
  // int mx=-1;
  REP(i, n) { cin >> p[i]; }
  int mn = p[0];
  int ans = 1;
  FOR(i, 1, n) {
    if (mn > p[i]) {
      ans++;
      mn = p[i];
    }
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b)                                                          \
  for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG2(x, y) cout << #x << ": " << x << " " << #y << ": " << y << endl
#define DEBUG_VEC(v)                                                           \
  cout << #v << ":";                                                           \
  REP(i, v.size()) cout << " " << v[i];                                        \
  cout << endl
#define DEBUG_ARR(v, n)                                                        \
  cout << #v << ":";                                                           \
  REP(i, n) cout << " " << v[i];                                               \
  cout << endl
#define ALL(a) (a).begin(), (a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a) % MOD + MOD) % MOD

int n, s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int p[200010];
  // int mx=-1;
  REP(i, n) { cin >> p[i]; }
  int mn = p[0];
  int ans = 1;
  FOR(i, 1, n) {
    if (mn > p[i]) {
      ans++;
      mn = p[i];
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int arr[N], mark[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> arr[i];
  mark[1] = arr[1];
  for (int i = 2; i <= n; i++) {
    mark[i] = min(mark[i - 1], arr[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (arr[i] <= mark[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int arr[N], mark[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> arr[i];
  mark[1] = arr[1];
  for (int i = 2; i <= n; i++) {
    mark[i] = min(mark[i - 1], arr[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (arr[i] <= mark[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define reppe(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)
#define repme(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)

typedef long long ll;

long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  return GCD(b, a % b);
}

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  repp(i, 0, N) cin >> P[i];
  int res = 0;
  repp(i, 0, N) {
    bool b = true;
    reppe(j, 0, i) { b &= P[j] >= P[i]; }
    if (b)
      ++res;
  }
  cout << res << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define reppe(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)
#define repme(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)

typedef long long ll;

long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  return GCD(b, a % b);
}

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  repp(i, 0, N) cin >> P[i];
  int res = 1;
  int minN = P[0];
  repp(i, 1, N) {
    if (minN > P[i])
      res++;
    minN = min(minN, P[i]);
  }
  cout << res << endl;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define debug(x) cerr << #x << ' ' << x << '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int book[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, cnt = 0;
  cin >> n;
  rep(i, 1, n) cin >> book[i];
  int Min = inf;
  rep(i, 1, n) {
    if (book[i] < Min) {
      Min = book[i];
      cnt++;
    }
  }
  cout << cnt << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define debug(x) cerr << #x << ' ' << x << '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int book[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, cnt = 0;
  cin >> n;
  rep(i, 1, n) cin >> book[i];
  int Min = inf;
  rep(i, 1, n) {
    if (book[i] < Min) {
      Min = book[i];
      cnt++;
    }
  }
  cout << cnt << '\n';
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10;
int a[M];

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int mn = a[1];
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    if (mn < a[i])
      ans++;
    mn = min(mn, a[i]);
  }
  cout << n - ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 10;
int a[M];

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int mn = a[1];
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    if (mn < a[i])
      ans++;
    mn = min(mn, a[i]);
  }
  cout << n - ans << endl;
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
using namespace std;
#define N 50000
#define nmax 50000
#define INFTY 100000

int n;
int num[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    num[i] = a;
  }
  int count = 1;
  int memo = num[0];
  for (int i = 1; i < n; i++) {
    if (memo > num[i]) {
      count += 1;
      memo = num[i];
    }
  }
  cout << count << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
using namespace std;
#define N 500000
#define nmax 50000
#define INFTY 100000

int n;
int num[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    num[i] = a;
  }
  int count = 1;
  int memo = num[0];
  for (int i = 1; i < n; i++) {
    if (memo > num[i]) {
      count += 1;
      memo = num[i];
    }
  }
  cout << count << endl;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)

int main(int argc, char **argv) {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, P[111111], C = 0;

  std::cin >> N;

  for (int i = 0; i < N; i++)
    std::cin >> P[i];

  std::set<int> set;

  for (int i = 0; i < N; i++) {
    if (set.empty()) {
      C++;
    } else if (*set.begin() >= P[i]) {
      C++;
    }

    set.insert(P[i]);
  }

  std::cout << C << std::endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)

int main(int argc, char **argv) {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, P[222222], C = 0;

  std::cin >> N;

  for (int i = 0; i < N; i++)
    std::cin >> P[i];

  std::set<int> set;

  for (int i = 0; i < N; i++) {
    if (set.empty()) {
      C++;
    } else if (*set.begin() >= P[i]) {
      C++;
    }

    set.insert(P[i]);
  }

  std::cout << C << std::endl;

  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int a[maxn];
void fl() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
int main() {
  //    fl();
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int minn = INF, ans = 0;
  for (int i = 1; i <= n; i++) {
    minn = min(minn, a[i]);
    if (minn >= a[i])
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int a[2 * maxn];
void fl() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
int main() {
  //    fl();
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int minn = INF, ans = 0;
  for (int i = 1; i <= n; i++) {
    minn = min(minn, a[i]);
    if (minn >= a[i])
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
const ll INF = 1e18;
const int maxn = 2e5 + 10;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll int n, m, a[maxn], i;
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  ll int mini = a[1], c = 1;
  for (i = 2; i <= n; i++) {
    if (a[i] <= mini)
      c++;
    mini = min(mini, a[i]);
  }
  cout << c;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
const ll INF = 1e18;
const int maxn = 2e5 + 10;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll int n, m, a[maxn], i;
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  ll int mini = a[1], c = 1;
  for (i = 2; i <= n; i++) {
    if (a[i] <= mini)
      c++;
    mini = min(mini, a[i]);
  }
  cout << c;
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)n; i++)

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int ans = 0;
  int nowMin = p[0];
  rep(i, n) {
    if (i != 0 && nowMin == 1)
      break;
    if (p[i] > nowMin) {
      continue;
    }
    bool ok = true;
    for (int j = 0; j < i; j++) {
      if (p[i] > p[j]) {
        ok = false;
        break;
      }
    }
    if (ok)
      ans++;
    nowMin = max(nowMin, p[i]);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)n; i++)

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int ans = 0;
  int nowMin = p[0];
  rep(i, n) {
    if (i != 0 && nowMin == 1)
      break;
    if (p[i] > nowMin) {
      continue;
    }
    ans++;
    nowMin = min(nowMin, p[i]);
  }
  cout << ans << endl;
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repe(i, n) for (int i = 0; i <= n; ++i)
#define repr(i, n) for (int i = n - 1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using V = vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int n, p;
  cin >> n;
  vector<int> P;
  vector<int> PP;
  int cnt = 0;
  rep(i, n) {
    cin >> p;
    P.pb(p);
    if (p == *min_element(all(P))) {
      cnt++;
    }
  }
  cout << cnt << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repe(i, n) for (int i = 0; i <= n; ++i)
#define repr(i, n) for (int i = n - 1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using V = vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int n, p;
  cin >> n;
  vector<int> P;
  vector<int> PP;
  int cnt = 0;
  rep(i, n) {
    cin >> p;
    P.pb(p);
  }
  int minn = INF;
  rep(i, P.size()) {
    if (P[i] < minn) {
      minn = P[i];
      cnt++;
    }
  }
  cout << cnt << "\n";
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)

int main() {
  int n;
  cin >> n;
  int p[n];
  int ans = 1;
  cin >> p[0];
  rep1(i, n) {
    cin >> p[i];
    bool ok = true;
    rep(j, i) {
      if (p[j] < p[i])
        ok = false;
      continue;
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)

int main() {
  int n;
  cin >> n;
  int ans = 0;
  int m = 1e8;
  rep(i, n) {
    int p;
    cin >> p;
    m = min(m, p);
    if (p == m)
      ans++;
  }
  cout << ans << endl;
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main() {
  int N;
  cin >> N;
  vector<int> P(N);
  rep(i, N) cin >> P[i];
  int cnt = 0;
  rep(i, N) {
    bool can = true;
    rep(j, i) {
      if (P[i] > P[j]) {
        can = false;
        break;
      }
    }
    if (can)
      cnt++;
  }
  cout << cnt;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main() {
  int N;
  cin >> N;
  vector<int> P(N);
  rep(i, N) cin >> P[i];
  int cnt = N;
  int min = P[0];
  rep(i, N - 1) {
    if (P[i + 1] > min)
      cnt--;
    else
      min = (min, P[i + 1]);
  }
  cout << cnt;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  // 1番目の数を見て、それよりも小さい数はいくつあるかを判定する
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
    cin >> vec.at(i);

  int ans = 0;
  int a = 0;
  a = vec.at(1);
  for (int i = 0; i < N; i++) {
    if (a >= vec.at(i)) {
      a = vec.at(i);
      ans++;
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  // 1番目の数を見て、それよりも小さい数はいくつあるかを判定する
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
    cin >> vec.at(i);

  int ans = 0;
  int a = 0;
  a = vec.at(0);
  for (int i = 0; i < N; i++) {
    if (a >= vec.at(i)) {
      a = vec.at(i);
      ans++;
    }
  }

  cout << ans << endl;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c)                                                             \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class BIT {
  int n;
  std::vector<int> bit;

public:
  BIT(int n) : n(n), bit(n + 1, 0) {}

  int sum(int i) {
    int s = 0;
    while (i > 0) {
      s += bit[i];
      i -= i & (-i);
    }
    return s;
  }
  void add(int i, int x) {
    while (i <= n) {
      bit[i] += x;
      i += i & (-i);
    }
  }
};

int main() {
  int N;
  cin >> N;
  vector<int> v;
  rep(i, N) {
    int a;
    cin >> a;
    v.push_back(a);
  }

  BIT bit(1 << 17);

  int ret = 0;
  rep(i, N) {
    bit.add(v[i], 1);
    if (bit.sum(v[i] - 1) == 0)
      ret++;
  }

  cout << ret << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c)                                                             \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class BIT {
  int n;
  std::vector<int> bit;

public:
  BIT(int n) : n(n), bit(n + 1, 0) {}

  int sum(int i) {
    int s = 0;
    while (i > 0) {
      s += bit[i];
      i -= i & (-i);
    }
    return s;
  }
  void add(int i, int x) {
    while (i <= n) {
      bit[i] += x;
      i += i & (-i);
    }
  }
};

int main() {
  int N;
  cin >> N;
  vector<int> v;
  rep(i, N) {
    int a;
    cin >> a;
    v.push_back(a);
  }

  BIT bit(N + 100);

  int ret = 0;
  rep(i, N) {
    bit.add(v[i], 1);
    if (bit.sum(v[i] - 1) == 0)
      ret++;
  }

  cout << ret << endl;

  return 0;
}
Problem p02791 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))
print(1 + sum([int(P[i] <= min(P[:i])) for i in range(1, N)]))


Fixed submission:
N = int(input())
P = list(map(int, input().split()))
Q = []
m = 10**17
for p in P:
    m = min(m, p)
    Q.append(m)
c = 0
for x, y in zip(P, Q):
    if x <= y:
        c += 1
print(c)
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>;  // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n, k, x, y;

// Bitと転倒数
class Bit {
public:
  ll size;
  vector<ll> data;
  Bit(ll num) {
    data.resize(num + 1);
    REP(i, num + 1)
    data[i] = 0;
    size = num;
  }
  //(1-i)までの合計を返す
  ll Sum(ll i) {
    ll s = 0;
    while (i > 0) {
      s += data[i];
      i -= i & (-i);
    }
    return s;
  }
  // Add
  void Add(ll i, ll x) {
    while (i <= size) {
      data[i] += x;
      i += i & (-i);
    }
  }
};

int main() {
  ll ans = 0;
  cin >> n;

  vi a(n);
  Bit bit(65536);

  REP(i, n) {
    cin >> a[i];
    bit.Add(a[i], 1);
    if (bit.Sum(a[i]) == 1)
      ans++;
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>;  // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n, k, x, y;

// Bitと転倒数
class Bit {
public:
  ll size;
  vector<ll> data;
  Bit(ll num) {
    data.resize(num + 1);
    REP(i, num + 1)
    data[i] = 0;
    size = num;
  }
  //(1-i)までの合計を返す
  ll Sum(ll i) {
    ll s = 0;
    while (i > 0) {
      s += data[i];
      i -= i & (-i);
    }
    return s;
  }
  // Add
  void Add(ll i, ll x) {
    while (i <= size) {
      data[i] += x;
      i += i & (-i);
    }
  }
};

int main() {
  ll ans = 0;
  cin >> n;

  vi a(n);
  Bit bit(262144);

  REP(i, n) {
    cin >> a[i];
    bit.Add(a[i], 1);
    if (bit.Sum(a[i]) == 1)
      ans++;
  }

  cout << ans << endl;
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, i, j, k, x = 1e6, cnt = 0;

  cin >> n;
  int p[n];
  for (i = 0; i < n; i++)
    cin >> p[i];

  for (i = 0; i < n; i++) {
    if (p[i] <= x) {
      x = p[i];
      cnt++;
    }
  }
  cout << cnt << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {

  /*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif*/
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, i, j, k, x = 1e6, cnt = 0;

  cin >> n;
  int p[n];
  for (i = 0; i < n; i++)
    cin >> p[i];

  for (i = 0; i < n; i++) {
    if (p[i] <= x) {
      x = p[i];
      cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
#define sort(s) sort(s.begin(), s.end())
#define r(s) reverse(s.begin(), s.end())
#define come return
constexpr auto AC = 0;
using namespace std;
int aa(vector<int> s, int i) {
  rep(j, i) {
    if (s[j] <= s[i])
      return 0;
  }
  return 1;
}

int main() {
  int a;
  int ans = 0;
  cin >> a;
  vector<int> s(a), t(a - 1);

  rep(i, a) {
    cin >> s[i];
    if (i == 0)
      t[i] = s[i];
    else
      t[i] = min(t[i - 1], s[i]);

    if (t[i] >= s[i])
      ans++;
  }
  cout << ans << endl;
  come AC;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
#define sort(s) sort(s.begin(), s.end())
#define r(s) reverse(s.begin(), s.end())
#define come return
constexpr auto AC = 0;
using namespace std;
int aa(vector<int> s, int i) {
  rep(j, i) {
    if (s[j] <= s[i])
      return 0;
  }
  return 1;
}

int main() {
  int a;
  int ans = 0;
  cin >> a;
  vector<int> s(a), t(a);

  rep(i, a) {
    cin >> s[i];
    if (i == 0)
      t[i] = s[i];
    else
      t[i] = min(t[i - 1], s[i]);

    if (t[i] >= s[i])
      ans++;
  }
  cout << ans << endl;
  come AC;
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++)
    cin >> p.at(i);
  int ans = 1;
  for (int i = n - 1; i > 0; i--) {

    for (int j = i - 1; j >= 0; j--) {
      if (p.at(i) > p.at(j)) {
        break;
      }
      if (j == 0)
        ans++;
    }
  }
  cout << ans;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++)
    cin >> p.at(i);
  int ans = 1;
  int r = p.at(0);
  for (int i = 1; i < n; i++) {
    if (r > p.at(i)) {
      ans++;
      r = p.at(i);
    }
  }
  cout << ans;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <climits> /* LLONG_MAX */
#include <cmath>

#include <algorithm>
#include <iomanip> /* setprecision */
#include <iostream>
#include <numeric> /* gcd, lcm, partial_sum, reduce*/
#include <string>
#include <vector>

using ll = long long; // c++11

const std::string ans[2] = {"No\n", "Yes\n"};

int main() {
  using namespace std;
  int n;
  cin >> n;
  vector<int> P;
  for (int i = 0; i < n; i++)
    cin >> P[i];

  int min_p = P[0];
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (P[i] < min_p) {
      min_p = P[i];
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <climits> /* LLONG_MAX */
#include <cmath>

#include <algorithm>
#include <iomanip> /* setprecision */
#include <iostream>
#include <numeric> /* gcd, lcm, partial_sum, reduce*/
#include <string>
#include <vector>

using ll = long long; // c++11

const std::string ans[2] = {"No\n", "Yes\n"};

int main() {
  using namespace std;
  int n;
  cin >> n;
  vector<int> P;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    P.push_back(p);
  }

  int min_p = P[0];
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (P[i] < min_p) {
      min_p = P[i];
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep_rev(n, i) for (ll i = n; i >= 0; --i)
using namespace std;
const long long INF = 1LL << 60;

ll N, m = INF, c = 0;
ll P[100100];

int main() {
  cin >> N;
  rep(i, N) cin >> P[i];
  rep(i, N) {
    if (m > P[i]) {
      m = P[i];
      c++;
    }
  }
  cout << c << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep_rev(n, i) for (ll i = n; i >= 0; --i)
using namespace std;
const long long INF = 1LL << 60;

ll N, m = INF, c = 0;
ll P[200010];

int main() {
  cin >> N;
  rep(i, N) cin >> P[i];
  rep(i, N) {
    if (m > P[i]) {
      m = P[i];
      c++;
    }
  }
  cout << c << endl;
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <math.h>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
  }

  int ans = n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      if (p.at(i) > p.at(j)) {
        ans--;
        break;
      }
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include <iostream>
#include <math.h>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
  }

  int ans = n;
  int mini = n;
  for (int i = 0; i < p.size(); i++) {
    mini = min(mini, p.at(i));
    if (mini != p.at(i)) {
      ans--;
    }
  }

  cout << ans << endl;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

struct SegmentTree {
  int n;
  int type;
  vector<int> st;
  int NEUTRO;
  void init(int _, int __, int ___) {
    n = _;
    st.resize(2 * _);
    NEUTRO = ___;
    type = __;
  }
  SegmentTree() {}

  int ope(int x, int y) {
    if (type == 0)
      return max(x, y);
    if (type == 1)
      return min(x, y);
    if (type == 2)
      return x + y;
    return 0;
  }

  void update(int pos, int value) {
    for (st[pos += n] = value; pos > 1; pos >>= 1) {
      st[pos >> 1] = ope(st[pos], st[pos ^ 1]);
    }
  }
  // interval[l,r)
  int query(int l, int r) {
    int ans = NEUTRO;
    r++;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1)
        ans = ope(ans, st[l++]);
      if (r & 1)
        ans = ope(ans, st[--r]);
    }
    return ans;
  }
};

int v[200010];

int main() {

  int n;
  cin >> n;

  for (int i = 0; i < n; ++i)
    cin >> v[i];

  SegmentTree st;
  st.init(n, 2, 0);

  int ans = 0;

  for (int i = 0; i < n; ++i) {
    st.update(v[i], 1);
    ans += (st.query(v[i], n) == i + 1);
  }
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

struct SegmentTree {
  int n;
  int type;
  vector<int> st;
  int NEUTRO;
  void init(int _, int __, int ___) {
    n = _;
    st.resize(5 * _);
    NEUTRO = ___;
    type = __;
  }
  SegmentTree() {}

  int ope(int x, int y) {
    if (type == 0)
      return max(x, y);
    if (type == 1)
      return min(x, y);
    if (type == 2)
      return x + y;
    return 0;
  }

  void update(int pos, int value) {
    for (st[pos += n] = value; pos > 1; pos >>= 1) {
      st[pos >> 1] = ope(st[pos], st[pos ^ 1]);
    }
  }
  // interval[l,r)
  int query(int l, int r) {
    int ans = NEUTRO;
    r++;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1)
        ans = ope(ans, st[l++]);
      if (r & 1)
        ans = ope(ans, st[--r]);
    }
    return ans;
  }
};

int v[200010];

int main() {

  int n;
  cin >> n;

  for (int i = 0; i < n; ++i)
    cin >> v[i];

  SegmentTree st;
  st.init(n, 2, 0);

  int ans = 0;

  for (int i = 0; i < n; ++i) {
    st.update(v[i], 1);
    ans += (st.query(v[i], n) == i + 1);
  }
  cout << ans << "\n";
  return 0;
}