alexjercan/bugnet huggingface dataset:
Problem p02435 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <typename T = lint> inline T in() {
  T x;
  cin >> x;
  return x;
}
#define INF 1e9
#define INFL static_cast<lint>(INF)
#define REP(i, n) for (lint i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (lint i = 1, i##_len = (n); i <= i##_len; ++i)
#define REPI(i, ini, n) for (lint i = (ini), i##_len = (n); i < i##_len; ++i)
#define REPC(i, obj) for (auto i : obj)
#define R_UP(a, b) (((a) + (b)-1) / (b))
#define ALL(obj) (obj).begin(), (obj).end()
int main() {
  int n = in(), q = in();
  vector<stack<int>> s(n);
  REP(i, q) {
    int t, x;
    switch (in()) {
    case 0:
      t = in(), x = in();
      s[t].push(x);
      break;
    case 1:
      t = in();
      if (s[t].size() != 0)
        cout << s[t].top() << endl;
      break;
    case 2:
      t = in();
      if (s[t].size() != 0)
        s[t].pop();
      break;
    }
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <typename T = lint> inline T in() {
  T x;
  cin >> x;
  return x;
}
#define INF 1e9
#define INFL static_cast<lint>(INF)
#define REP(i, n) for (lint i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (lint i = 1, i##_len = (n); i <= i##_len; ++i)
#define REPI(i, ini, n) for (lint i = (ini), i##_len = (n); i < i##_len; ++i)
#define REPC(i, obj) for (auto i : obj)
#define R_UP(a, b) (((a) + (b)-1) / (b))
#define ALL(obj) (obj).begin(), (obj).end()
int main() {
  int n = in(), q = in();
  vector<stack<int>> s(n);
  REP(i, q) {
    int t, x;
    switch (in()) {
    case 0:
      t = in(), x = in();
      s[t].push(x);
      break;
    case 1:
      t = in();
      if (s[t].size() != 0)
        cout << s[t].top() << endl;
      break;
    case 2:
      t = in();
      s[t].pop();
      break;
    }
  }
}
Problem p02435 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stack>
using namespace std;

int main() {

  int n, q, command, t, x;

  cin >> n;
  stack<int> S[n];

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> command;

    if (command == 0) {
      cin >> t >> x;
      S[t].push(x);
    } else if (command == 1) {
      cin >> t;
      if (S[t].size())
        cout << S[t].top() << endl;
    } else if (command == 2) {
      cin >> t;
      if (S[t].size())
        S[t].pop();
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stack>
using namespace std;

int main() {

  int n, q, command, t, x;

  cin >> n;
  stack<int> S[n];

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> command;

    if (command == 0) {
      cin >> t >> x;
      S[t].push(x);
    } else if (command == 1) {
      cin >> t;
      cout << S[t].top() << endl;
    } else if (command == 2) {
      cin >> t;
      S[t].pop();
    }
  }

  return 0;
}
Problem p02435 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>
using namespace std;

int main() {
  int n, q, t, x, y;
  cin >> n >> q;
  stack<int> a[n];
  for (int i = 0; i < q; i++) {
    cin >> t;
    if (t == 0) {
      cin >> x >> y;
      a[x].push(y);
    }
    if (t == 1) {
      cin >> x;
      if (!a[x].empty())
        cout << a[x].top() << endl;
    }
    if (t == 2) {
      cin >> x;
      if (!a[x].empty())
        a[x].pop();
    }
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
#include <stack>
using namespace std;

int main() {
  int n, q, t, x;
  cin >> n >> q;
  stack<int> a[n];
  for (int i = 0; i < q; i++) {
    if (i == 0) {
      cin >> t >> x;
      a[t].push(x);
    }
    if (i == 1) {
      cin >> t;
      cout << a[t].top() << endl;
    }
    if (i == 2) {
      cin >> t;
      a[t].pop();
    }
  }
  return 0;
}
Problem p02435 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, q;
  cin >> n >> q;
  vector<stack<int>> vs(n);
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    if (a == 0) {
      int t, x;
      cin >> t >> x;
      vs.at(t).push(x);
    }
    if (a == 1) {
      int t;
      cin >> t;
      if (!vs.at(t).empty())
        cout << vs.at(t).top() << endl;
    }
    if (a == 2) {
      int t;
      cin >> t;
      if (!vs.at(t).empty())
        vs.at(t).pop();
    }
  }
}


Error: 0

Fixed submission:

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

int main() {
  int n, q;
  cin >> n >> q;
  vector<stack<int>> vs(n);
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    if (a == 0) {
      int t, x;
      cin >> t >> x;
      vs.at(t).push(x);
    }
    if (a == 1) {
      int t;
      cin >> t;
      cout << vs.at(t).top() << endl;
    }
    if (a == 2) {
      int t;
      cin >> t;
      if (!vs.at(t).empty())
        vs.at(t).pop();
    }
  }
}
Problem p02435 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

vector<stack<int>> st;

void f0() {
  int p1, p2;
  cin >> p1 >> p2;

  st[p1].push(p2);
}

void f1() {
  int p;
  cin >> p;

  if (!st[p].empty())
    cout << st[p].top() << endl;
}

void f2() {
  int p;
  cin >> p;

  if (!st[p].empty())
    st[p].pop();
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;

  cin >> n >> q;

  st.resize(n);

  while (q--) {
    int op;
    cin >> op;

    switch (op) {
    case 0:
      f0();
      break;
    case 1:
      f1();
      break;
    case 2:
      f2();
      break;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

vector<stack<int>> st;

void f0() {
  int p1, p2;
  cin >> p1 >> p2;

  st[p1].push(p2);
}

void f1() {
  int p;
  cin >> p;

  cout << st[p].top() << endl;
}

void f2() {
  int p;
  cin >> p;

  if (!st[p].empty())
    st[p].pop();
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;

  cin >> n >> q;

  st.resize(n);

  while (q--) {
    int op;
    cin >> op;

    switch (op) {
    case 0:
      f0();
      break;
    case 1:
      f1();
      break;
    case 2:
      f2();
      break;
    }
  }

  return 0;
}
Problem p02435 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  vector<stack<int>> stk(n);
  while (q--) {
    int k, t;
    cin >> k >> t;
    if (k == 0) {
      int x;
      cin >> x;
      stk[t].push(x);
    } else if (k == 1) {
      if (stk[t].empty())
        continue;
      cout << stk[t].top() << endl; // error
    } else if (k == 2) {
      if (stk[t].empty())
        continue;
      stk[t].pop(); // error
    } else {
      assert(false);
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  vector<stack<int>> stk(n);
  while (q--) {
    int k, t;
    cin >> k >> t;
    if (k == 0) {
      int x;
      cin >> x;
      stk[t].push(x);
    } else if (k == 1) {
      cout << stk[t].top() << endl; // error
    } else if (k == 2) {
      stk[t].pop(); // error
    } else {
      assert(false);
    }
  }
  return 0;
}
Problem p02435 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
// INSERT ABOVE HERE
signed main() {
  int n, q;
  cin >> n >> q;
  vector<stack<int>> s(n);
  for (int i = 0; i < q; i++) {
    int t, a;
    cin >> t >> a;
    if (t == 0) {
      int x;
      cin >> x;
      s[a].emplace(x);
    }
    if (t == 1)
      if (!s[a].empty())
        cout << s[a].top() << endl;
    if (t == 2)
      if (!s[a].empty())
        s[a].pop();
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
// INSERT ABOVE HERE
signed main() {
  int n, q;
  cin >> n >> q;
  vector<stack<int>> s(n);
  for (int i = 0; i < q; i++) {
    int t, a;
    cin >> t >> a;
    if (t == 0) {
      int x;
      cin >> x;
      s[a].emplace(x);
    }
    if (t == 1)
      cout << s[a].top() << endl;
    if (t == 2)
      s[a].pop();
  }
  return 0;
}
Problem p02435 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  stack<int> s[n];
  while (q--) {
    int a, b, c;
    cin >> a >> b;
    if (!a) {
      cin >> c;
      s[b].push(c);
    } else if (a == 1) {
      if (!s[b].empty())
        cout << s[b].top() << endl;
    } else if (!s[b].empty())
      s[b].pop();
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  stack<int> s[n];
  while (q--) {
    int a, b, c;
    cin >> a >> b;
    if (!a) {
      cin >> c;
      s[b].push(c);
    } else if (a == 1) {
      cout << s[b].top() << endl;
    } else if (!s[b].empty())
      s[b].pop();
  }
}
Problem p02435 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {

  int n, q;
  cin >> n >> q;

  vector<stack<int>> s(n);

  for (int i = 0; i < q; i++) {

    int a, t, x;
    cin >> a;
    if (a == 0) {
      cin >> t >> x;

      s[t].push(x);
    }

    if (a == 1) {
      cin >> t;
      if (!s[t].empty()) {
        cout << s[t].top() << endl;
      }
    }

    if (a == 2) {
      cin >> t;
      if (!s[t].empty()) {
        s[t].pop();
      }
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {

  int n, q;
  cin >> n >> q;

  vector<stack<int>> s(n);

  for (int i = 0; i < q; i++) {

    int a, t, x;
    cin >> a;
    if (a == 0) {
      cin >> t >> x;

      s[t].push(x);
    }

    if (a == 1) {
      cin >> t;
      if (!s[t].empty()) {
        cout << s[t].top() << endl;
      }
    }

    if (a == 2) {
      cin >> t;
      s[t].pop();
    }
  }

  return 0;
}
Problem p02435 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lpin(a, i, n)                                                          \\
  for (int i = 0; i < n; i++) {                                                \\
    cin >> a[i];                                                               \\
  }

int main() {
  stack<int> v[1000];
  int n, q;
  cin >> n >> q;
  lp(i, q) {
    int a, b, c;
    cin >> a >> b;
    if (a == 0) {
      cin >> c;
      v[b].push(c);
    }
    if (a == 1) {
      if (v[b].empty())
        1;
      else
        cout << v[b].top() << endl;
    }
    if (a == 2) {
      if (v[b].empty())
        1;
      else
        v[b].pop();
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lpin(a, i, n)                                                          \\
  for (int i = 0; i < n; i++) {                                                \\
    cin >> a[i];                                                               \\
  }

int main() {
  stack<int> v[1000];
  int n, q;
  cin >> n >> q;
  lp(i, q) {
    int a, b, c;
    cin >> a >> b;
    if (a == 0) {
      cin >> c;
      v[b].push(c);
    }
    if (a == 1) {
      cout << v[b].top() << endl;
    }
    if (a == 2) {
      v[b].pop();
    }
  }
  return 0;
}
Problem p02437 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  vector<priority_queue<int>> que(n);
  while (q--) {
    int k, t;
    cin >> k >> t;
    if (k == 0) {
      int x;
      cin >> x;
      que[t].push(x);
    } else if (k == 1) {
      if (que[t].empty())
        continue;
      cout << que[t].top() << endl;
    } else if (k == 2) {
      if (que[t].empty())
        continue;
      que[t].pop();
    } else {
      assert(false);
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  vector<priority_queue<int>> que(n);
  while (q--) {
    int k, t;
    cin >> k >> t;
    if (k == 0) {
      int x;
      cin >> x;
      que[t].push(x);
    } else if (k == 1) {
      cout << que[t].top() << endl;
    } else if (k == 2) {
      que[t].pop();
    } else {
      assert(false);
    }
  }
  return 0;
}
Problem p02437 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#define long long long
#define LF '\\n'
using namespace std;
typedef pair<int, int> pii;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a ? a = b, 1 : 0;
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a ? a = b, 1 : 0;
}
constexpr int INF = 0x3f3f3f3f;

priority_queue<int> pq[1005];

signed main() {
  cin.tie(nullptr), ios::sync_with_stdio(false);

  int n, q;
  cin >> n >> q;

  while (q--) {
    int com, t, x;
    cin >> com;

    if (com == 0) {
      cin >> t >> x;
      pq[t].emplace(x);
    } else if (com == 1) {
      cin >> t;
      if (pq[t].size())
        cout << pq[t].top() << LF;
    } else {
      cin >> t;
      if (pq[t].size())
        pq[t].pop();
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#define long long long
#define LF '\\n'
using namespace std;
typedef pair<int, int> pii;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a ? a = b, 1 : 0;
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a ? a = b, 1 : 0;
}
constexpr int INF = 0x3f3f3f3f;

priority_queue<int> pq[1005];

signed main() {
  cin.tie(nullptr), ios::sync_with_stdio(false);

  int n, q;
  cin >> n >> q;

  while (q--) {
    int com, t, x;
    cin >> com;

    if (com == 0) {
      cin >> t >> x;
      pq[t].emplace(x);
    } else if (com == 1) {
      cin >> t;
      cout << pq[t].top() << LF;
    } else {
      cin >> t;
      if (pq[t].size())
        pq[t].pop();
    }
  }

  return 0;
}
Problem p02438 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define all(x) x.begin(), x.end()
using namespace std;
struct S {
  int num = mod;
  vector<S *> list;
};
S top[1234];
S ss[510000];
int sssize = 0;
int n, q;
void ssinsert(S s1) {
  ss[sssize] = s1;
  sssize++;
}

bool dumpb = 0;
void dump(S *s1) {
  if ((*s1).num != mod) {
    if (dumpb)
      cout << ' ';
    cout << (*s1).num;
    dumpb = 1;
  }
  for (S *s2 : (*s1).list)
    dump(s2);
}

signed main() {
  cin >> n >> q;
  for1(valsqotch, q) {
    int a, b, c;
    cin >> a;
    if (a == 0) {
      S s1;
      cin >> b >> s1.num;
      ssinsert(s1);
      top[b].list.push_back(&(ss[sssize - 1]));
    } else if (a == 1) {
      cin >> b;
      dump(&(top[b]));
      cout << endl;
      dumpb = 0;
    } else {
      cin >> b >> c;
      S s1 = top[b];
      ssinsert(s1);
      top[c].list.push_back(&(ss[sssize - 1]));
      top[b].list.clear();
    }
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define int long long
using namespace std;
vector<int> v[1001];
void splice(int p, int q) {
  for (int i = 0; i < v[q].size(); i++)
    v[p].push_back(v[q][i]);
  v[q].clear();
  return;
}
signed main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    int t, x;
    cin >> n;
    if (n == 0) {
      cin >> t >> x;
      v[t].push_back(x);
    } else if (n == 1) {
      cin >> t;
      for (int i = 0; i < v[t].size(); i++)
        if (i)
          cout << ' ' << v[t][i];
        else
          cout << v[t][i];
      cout << endl;
    } else {
      cin >> t >> x;
      splice(x, t);
    }
  }
}
Problem p02438 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
// #define int ll
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
template <class T> using V = vector<T>;
template <class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (ll i = (ll)(b)-1; i >= a; --i)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9 + 7;
void cioacc() { // accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
void printvec(list<int> a) {
  if (a.empty()) {
    cout << endl;
    return;
  }
  for (auto itr = a.begin(); itr != a.end(); ++itr) {
    auto itr2 = itr;
    itr2++;
    if (itr2 == a.end())
      cout << *itr << endl;
    else
      cout << *itr << " ";
  }
}
signed main() {
  int n;
  cin >> n;
  vector<list<int>> v(n);
  int q;
  cin >> q;
  REP(i, q) {
    int d, t;
    cin >> d >> t;
    if (d == 0) {
      int x;
      cin >> x;
      v[t].eb(x);
    } else if (d == 1) {
      printvec(v[t]);
    } else {
      int s;
      cin >> s;
      v[s].splice(v[s].end(), v[t]);
      v[t].clear();
    }
  }
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
// #define int ll
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
template <class T> using V = vector<T>;
template <class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (ll i = (ll)(b)-1; i >= a; --i)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9 + 7;
void cioacc() { // accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
void printvec(vi a) {
  if (a.empty()) {
    cout << endl;
    return;
  }
  REP(i, a.size() - 1) cout << a[i] << " ";
  cout << a.back() << endl;
}
signed main() {
  int n;
  cin >> n;
  vvi v(n);
  int q;
  cin >> q;
  REP(i, q) {
    int d, t;
    cin >> d >> t;
    if (d == 0) {
      int x;
      cin >> x;
      v[t].eb(x);
    } else if (d == 1) {
      printvec(v[t]);
    } else {
      int s;
      cin >> s;
      v[s].insert(v[s].end(), v[t].begin(), v[t].end());
      v[t].clear();
    }
  }
}
Problem p02440 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
  int n, q;
  set<int> a;

  cin >> n;
  for (int i = 0, t; i < n && cin >> t; i++)
    a.insert(t);
  cin >> q;
  for (int i = 0, k; i < q; i++) {
    cin >> k;
    cout << (a.find(k) != a.end()) << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
  int n, q;
  set<int> a;

  cin >> n;
  for (int i = 0, t; i < n && cin >> t; i++)
    a.insert(t);
  cin >> q;
  for (int i = 0, k; i < q; i++) {
    cin >> k;
    cout << binary_search(a.begin(), a.end(), k) << endl;
  }

  return 0;
}
Problem p02440 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int c, b, e;
    cin >> c >> b >> e;
    if (c == 0) {
      int ans = 1000000001;
      for (int j = b; j < e; j++) {
        ans = min(ans, v.at(j));
      }
      cout << ans << endl;
    }
    if (c == 1) {
      int ans = -1000000001;
      for (int j = b; j < e; j++) {
        ans = max(ans, v.at(j));
      }
      cout << ans << endl;
    }
  }
}


Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int c, b, e;
    cin >> c >> b >> e;
    if (c == 0) {
      int ans = 1000000001;
      for (int j = b; j < b + e; j++) {
        ans = min(ans, v.at(j));
      }
      cout << ans << endl;
    }
    if (c == 1) {
      int ans = -1000000001;
      for (int j = b; j < b + e; j++) {
        ans = max(ans, v.at(j));
      }
      cout << ans << endl;
    }
  }
}
Problem p02440 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  int q;
  cin >> q;
  while (q--) {
    int com, b, e;
    cin >> com >> b >> e;
    if (com == 0) {
      cout << *min_element(a.begin() + b, a.begin() + e) << endl;
    } else if (com == 1) {
      cout << *max_element(a.begin() + b, a.begin() + e) << endl;
    } else {
      assert(false);
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  auto b = a;
  sort(b.begin(), b.end());
  assert(a == b);
  int q;
  cin >> q;
  while (q--) {
    int k;
    cin >> k;
    auto it = find(a.begin(), a.end(), k); // lower_bound(a.begin(), a.end(),
                                           // k);
    // cout << (it != a.end() && *it == k) << endl;
    cout << (it != a.end()) << endl;
  }
  return 0;
}
Problem p02441 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  cin >> q;
  for (int i = 0, k; i < q; i++) {
    cin >> k;
    cout << distance(a.begin(), lower_bound(a.begin(), a.end(), k)) << endl;
  }

  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  cin >> q;
  for (int i = 0, k; i < q; i++) {
    cin >> k;
    cout << distance(a.begin(), lower_bound(a.begin(), a.end(), k)) << endl;
  }

  return 0;
}
Problem p02445 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define name (i++ ? " " : "")
int main() {

  int n;
  cin >> n;

  vector<int> a(n);
  REP(i, n) cin >> a[i];

  int q;
  cin >> q;

  REP(i, q) {

    int b, e, t;
    cin >> b >> e >> t;

    swap_ranges(a.begin() + b, a.begin() + e, a.begin() + t);
  }

  int i = 0;
  for (int e : a)
    cout << name << e;
  cout << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <list>
using namespace std;
int main() {

  int q;
  list<int> a;
  auto it = a.end();
  cin >> q;
  for (int i = 0; i < q; i++) {
    int n;
    cin >> n;
    if (n == 2)
      a.erase(it), advance(it, 1);
    else if (n) {
      int d;
      cin >> d;
      advance(it, d);
    } else {
      int x;
      cin >> x;
      a.insert(it, x);
      advance(it, -1);
    }
  }
  for (int e : a)
    cout << e << endl;
  return 0;
}