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

#include <bits/stdc++.h>
using namespace std;
long long n, m, k, a[100005], dp[100005];
long long solve(long long p) {
  if (p > n)
    return 1LL << 62;
  if (p == n)
    return 0;
  if (dp[p] >= 1)
    return dp[p];
  long long p1 = 1LL << 62, p2 = 0, ret = 1LL << 62;
  for (int i = p + 1; i <= p + m; i++) {
    p1 = min(p1, a[i - 1]);
    p2 = max(p2, a[i - 1]);
    ret = min(ret, solve(i) + (p2 - p1) * (i - p) + k);
  }
  dp[p] = ret;
  return ret;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  cout << solve(0) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, m, k, a[20005], dp[20005];
long long solve(long long p) {
  if (p > n)
    return 1LL << 62;
  if (p == n)
    return 0;
  if (dp[p] >= 1)
    return dp[p];
  long long p1 = 1LL << 62, p2 = 0, ret = 1LL << 62;
  for (int i = p + 1; i <= p + m; i++) {
    p1 = min(p1, a[i - 1]);
    p2 = max(p2, a[i - 1]);
    ret = min(ret, solve(i) + (p2 - p1) * (i - p) + k);
  }
  dp[p] = ret;
  return ret;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  cout << solve(0) << endl;
  return 0;
}
Problem p00549 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
long long dp[110000][4], n;
string T;
char F[5] = "JOI!";
long long solve(string S) {
  for (int i = 0; i < 440000; i++)
    dp[i / 4][i % 4] = 0;
  dp[0][0] = 1;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < 4; j++) {
      if (F[j] == S[i])
        dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j] += dp[i][j];
    }
  }
  return dp[S.size()][3];
}
int main() {
  cin >> n >> T;
  long long J = 0, I = 0;
  for (int i = 0; i < T.size(); i++)
    if (T[i] == 'I')
      I++;
  int maxn = 0, maxid = 0;
  for (int j = 0; j < T.size(); j++) {
    if (T[j] == 'J')
      J++;
    if (T[j] == 'I')
      I--;
    if (J * I > maxn) {
      maxn = J * I;
      maxid = j + 1;
    }
  }
  string T1 = 'J' + T, T2 = T + 'I',
         T3 = T.substr(0, maxid) + 'O' + T.substr(maxid, T.size() - maxid);
  cout << max(solve(T1), max(solve(T2), solve(T3))) << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
long long dp[110000][4], n;
string T;
char F[5] = "JOI!";
long long solve(string S) {
  for (int i = 0; i < 440000; i++)
    dp[i / 4][i % 4] = 0;
  dp[0][0] = 1;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < 4; j++) {
      if (F[j] == S[i])
        dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j] += dp[i][j];
    }
  }
  return dp[S.size()][3];
}
int main() {
  cin >> n >> T;
  long long J = 0, I = 0;
  for (int i = 0; i < T.size(); i++)
    if (T[i] == 'I')
      I++;
  int maxn = 0, maxid = 0;
  for (int j = 0; j < T.size(); j++) {
    if (T[j] == 'J')
      J++;
    if (T[j] == 'I')
      I--;
    if (J * I > maxn) {
      maxn = J * I;
      maxid = j;
    }
  }
  cout << max(solve('J' + T),
              max(solve(T + 'I'), solve(T.substr(0, maxn) + 'O' +
                                        T.substr(maxn, T.size() - maxn))));
  return 0;
}
Problem p00549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int n;
string T;
vector<int> v;
long long search(string S) {
  v.clear();
  for (int i = 0; i < (int)S.size(); i++) {
    if (S[i] == 'J')
      v.push_back(0);
    if (S[i] == 'O')
      v.push_back(1);
    if (S[i] == 'I')
      v.push_back(2);
  }
  vector<vector<long long>> dp(v.size() + 1, vector<long long>(4, 0));
  dp[0][0] = 1;
  for (int i = 0; i < (int)v.size(); i++) {
    dp[i + 1][v[i] + 1] += dp[i][v[i]];
    for (int j = 0; j < 4; j++)
      dp[i + 1][j] += dp[i][j];
  }
  return dp[v.size()][3];
}
int main() {
  cin >> n >> T;
  long long ret = 0;
  ret = max(ret, max(search("J" + T), search(T + "I")));
  long long c1 = 0, c2 = 0, w = search(T);
  for (int i = 0; i < (int)T.size(); i++) {
    if (T[i] == 'I')
      c2++;
  }
  for (int i = 0; i < (int)T.size(); i++) {
    if (T[i] == 'J')
      c1++;
    if (T[i] == 'I')
      c2--;
    ret = max(ret, w + c1 * c2);
  }
  cout << ret << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n;
string T;
vector<int> v;
long long search(string S) {
  v.clear();
  for (int i = 0; i < (int)S.size(); i++) {
    if (S[i] == 'J')
      v.push_back(0);
    if (S[i] == 'O')
      v.push_back(1);
    if (S[i] == 'I')
      v.push_back(2);
  }
  vector<vector<int>> dp(v.size() + 1, vector<int>(4, 0));
  dp[0][0] = 1;
  for (int i = 0; i < (int)v.size(); i++) {
    dp[i + 1][v[i] + 1] += dp[i][v[i]];
    for (int j = 0; j < 4; j++)
      dp[i + 1][j] += dp[i][j];
  }
  return dp[v.size()][3];
}
int main() {
  cin >> n >> T;
  long long ret = 0;
  ret = max(ret, max(search("J" + T), search(T + "I")));
  for (int i = 1; i <= (int)T.size() - 1; i++) {
    ret = max(ret, search(T.substr(0, i) + "O" + T.substr(i, T.size() - i)));
  }
  cout << ret << endl;
  return 0;
}
Problem p00549 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
string S;
string ns;
const string JOI = "JOI#";

ll IC[100005];
ll JC[100005];

ll dp[100005][4];
ll solve(const string &s) {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < 4; j++) {
      if (s[i] == JOI[j])
        dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j] += dp[i][j];
    }
  }
  return dp[s.size()][3];
}

int main() {

  cin >> N;
  cin >> S;

  ll res = solve(S);

  S = "a" + S;

  for (int i = 1; i <= N; i++) {
    if (S[i] == 'J')
      JC[i] = JC[i - 1] + 1;
    else
      JC[i] = JC[i - 1];
  }

  for (int i = N; i >= 1; i--) {
    if (S[i] == 'I')
      IC[i] = IC[i + 1] + 1;
    else
      IC[i] = IC[i + 1];
  }

  ll lmax = 0;
  for (int i = 1; i <= N; i++) {
    lmax = max(lmax, JC[i] * IC[i]);
  }
  res = res + lmax;

  S = S.substr(1);
  ns = "J" + S;
  res = max(res, solve(ns));
  ns = S + "I";
  res = max(res, solve(ns));

  cout << res << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
string S;
string ns;
const string JOI = "JOI#";

ll IC[100005];
ll JC[100005];

ll dp[10005][4];
ll solve(const string &s) {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < 4; j++) {
      if (s[i] == JOI[j])
        dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j] += dp[i][j];
    }
  }
  return dp[s.size()][3];
}

int main() {

  cin >> N;
  cin >> S;

  ll res = solve(S);

  S = "a" + S;

  for (int i = 1; i <= N; i++) {
    if (S[i] == 'J')
      JC[i] = JC[i - 1] + 1;
    else
      JC[i] = JC[i - 1];
  }

  for (int i = N; i >= 1; i--) {
    if (S[i] == 'I')
      IC[i] = IC[i + 1] + 1;
    else
      IC[i] = IC[i + 1];
  }

  ll lmax = 0;
  for (int i = 1; i <= N; i++) {
    lmax = max(lmax, JC[i] * IC[i]);
  }
  res = res + lmax;

  S = S.substr(1);
  ns = "J" + S;
  res = max(res, solve(ns));
  ns = S + "I";
  res = max(res, solve(ns));

  cout << res << endl;
}
Problem p00549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using ll = long long int;

constexpr int MAX_N = 100000;

int n;
int street[MAX_N];

int sum;

int main() {
  std::cin >> n;
  char ch;
  for (int i = 0; i < n; ++i) {
    std::cin >> ch;
    if (ch == 'O') {
      street[i] = 1;
    } else if (ch == 'I') {
      street[i] = 2;
      ++sum;
    }
  }
  ll base = 0;
  int count = 0, count1 = 0;
  for (int i = 0; i < n; ++i) {
    if (!street[i])
      ++count;
    else if (street[i] == 1) {
      base += count * (sum - count1);
    } else if (street[i] == 2)
      ++count1;
  }
  ll ans = 0;

  count = 0;

  for (int i = 0; i < n; ++i) {
    if (!street[i])
      ++count;
    else if (street[i] == 1)
      ans += count;
  }

  count = 0;
  ll tmp = 0;

  for (int i = n - 1; i >= 0; --i) {
    if (street[i] == 2)
      ++count;
    else if (street[i] == 1)
      tmp += count;
  }

  ans = std::max(ans, tmp);

  tmp = 0;
  count = 0;
  count1 = 0;

  for (int i = 0; i < n; ++i) {
    if (!street[i])
      ++count;
    else if (street[i] == 2)
      ++count1;
    ans = std::max(ans, (ll)count * (sum - count1));
  }

  std::cout << ans + base << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

constexpr int MAX_N = (int)1e5;

int n;
int data[MAX_N];

int main() {
  std::cin >> n;
  char in;
  for (int i = 0; i < n; ++i) {
    std::cin >> in;
    if (in == 'O')
      data[i] = 1;
    else if (in == 'I')
      data[i] = 2;
  }
  int max = 0, cnt = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (data[i] == 1) {
      for (int j = i + 1; j < n; ++j) {
        if (data[j] == 2)
          ++cnt;
      }
    }
  }
  max = std::max(max, cnt);
  cnt = 0;
  for (int i = n - 1; i >= 1; --i) {
    if (data[i] == 1) {
      for (int j = i - 1; j >= 0; --j) {
        if (data[j] == 0)
          ++cnt;
      }
    }
  }
  max = std::max(max, cnt);
  int sum[MAX_N] = {0};
  for (int i = 0; i < n - 1; ++i) {
    if (data[i] == 0) {
      for (int j = i + 1; j < n; ++j) {
        if (data[j] == 2) {
          ++sum[i];
          --sum[j];
        }
      }
    }
  }
  for (int i = 1; i < n; ++i)
    sum[i] += sum[i - 1];
  cnt = 0;
  for (int i = 0; i < n; ++i)
    cnt = std::max(cnt, sum[i]);
  max = std::max(max, cnt);

  for (int i = 0; i < n; ++i) {
    if (data[i] == 1)
      max += sum[i];
  }
  std::cout << max << std::endl;
  return 0;
}
Problem p00549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

typedef long long int int64;

int N, C[100000][3];
string S;

int64 max(int64 a, int64 b) {
  if (a > b)
    return a;
  else
    return b;
}

int main(void) {
  cin >> N;
  cin >> S;
  int64 ci = 0;
  int64 cj = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'I')
      ci++;
    else if (S[i] == 'J')
      cj++;
  }
  int64 ja = 0;
  int64 oa = 0;
  int64 ia = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'O') {
      ja += ci;
    } else if (S[i] == 'I')
      ci--;
    C[i][2] = ci;
  }
  for (int i = N - 1; i >= 0; i--) {
    if (S[i] == 'O') {
      ia += cj;
    } else if (S[i] == 'J')
      cj--;
    C[i][0] = cj;
  }
  for (int i = 0; i < N - 1; i++) {
    oa = max(oa, C[i + 1][0] * C[i][2]);
  }
  int64 initial = 0;
  int64 sumo = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'O')
      sumo += C[i][2];
  }
  for (int i = 0; i < N; i++) {
    if (S[i] == 'J') {
      initial += sumo;
    } else if (S[i] == 'O') {
      sumo -= C[i][2];
    }
  }
  int64 res = initial + max(max(ja, ia), oa);
  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

typedef long long int int64;

int N, C[100000][3];
string S;

int64 max(int64 a, int64 b) {
  if (a > b)
    return a;
  else
    return b;
}

int main(void) {
  cin >> N;
  cin >> S;
  int64 ci = 0;
  int64 cj = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'I')
      ci++;
    else if (S[i] == 'J')
      cj++;
  }
  int64 ja = 0;
  int64 oa = 0;
  int64 ia = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'O') {
      ja += ci;
    } else if (S[i] == 'I')
      ci--;
    C[i][2] = ci;
  }
  for (int i = N - 1; i >= 0; i--) {
    if (S[i] == 'O') {
      ia += cj;
    } else if (S[i] == 'J')
      cj--;
    C[i][0] = cj;
  }
  for (int i = 0; i < N - 1; i++) {
    oa = max(oa, C[i + 1][0] * C[i][2]);
  }
  int64 initial = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'J') {
      for (int t = i; t < N; t++) {
        if (S[t] == 'O')
          initial += C[t][2];
      }
    }
  }
  int64 res = initial + max(max(ja, ia), oa);
  cout << res << endl;
}
Problem p00550 (C++) — buggy submission, verdict: Runtime Error

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

#define INF 1000000000
#define rep(i, n) for (int i = 1; i <= n; i++)
typedef pair<int, int> P;
int n, m, q;
vector<P> G[100002]; // i????????£??\\???????????¨????????????
int D[100002];       // i?????¨????????¢
int fuman[100002];   // i???????????´?????????????????±??????
int neage[200002];   //??????j????????´???????????????????????????
int ans[200002];     // j??´?????????????????±???????????°

int main() {
  cin >> n >> m >> q;
  rep(i, n) D[i] = INF;
  rep(i, m) neage[i] = INF;
  rep(i, m) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(P(i, v));
    G[v].push_back(P(i, u));
  }
  rep(j, q) {
    int r;
    cin >> r;
    neage[r] = j;
  }
  queue<int> que;
  que.push(1);
  D[1] = 0;
  fuman[1] = INF;
  while (!que.empty()) {
    int s = que.front();
    que.pop();
    for (P p : G[s]) {
      int r = p.first;
      int t = p.second;
      if (D[t] > D[s] + 1) {
        D[t] = D[s] + 1;
        fuman[t] = max(fuman[t], min(fuman[s], neage[r]));
        que.push(t);
      } else if (D[t] == D[s] + 1) {
        fuman[t] = max(fuman[t], min(fuman[s], neage[r]));
      }
    }
  }
  rep(i, n) {
    if (fuman[i] != INF)
      ans[fuman[i]]++;
  }
  int S = 0;
  rep(i, q) {
    S += ans[i];
    cout << S << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define INF 1000000000
#define rep(i, n) for (int i = 1; i <= n; i++)
typedef pair<int, int> P;
int n, m, q;
vector<P> G[100002]; // i????????£??\\???????????¨????????????
int D[100002];       // i?????¨????????¢
int fuman[100002];   // i???????????´?????????????????±??????
int neage[200002];   //??????j????????´???????????????????????????
int ans[200002];     // j??´?????????????????±???????????°

int main() {
  cin >> n >> m >> q;
  rep(i, n) D[i] = INF;
  rep(i, m) neage[i] = INF;
  rep(i, m) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(P(i, v));
    G[v].push_back(P(i, u));
  }
  rep(j, q) {
    int r;
    cin >> r;
    neage[r] = j;
  }
  queue<int> que;
  que.push(1);
  D[1] = 0;
  fuman[1] = INF;
  while (!que.empty()) {
    int s = que.front();
    que.pop();
    for (P p : G[s]) {
      int r = p.first;
      int t = p.second;
      if (D[t] >= D[s] + 1) {
        D[t] = D[s] + 1;
        fuman[t] = max(fuman[t], min(fuman[s], neage[r]));
        que.push(t);
      }
    }
  }
  rep(i, n) {
    if (fuman[i] != INF)
      ans[fuman[i]]++;
  }
  int S = 0;
  rep(i, q) {
    S += ans[i];
    cout << S << endl;
  }
  return 0;
}
Problem p00550 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#pragma warning(disable : 4996)
int n, m, q, a[210000], b[210000], c, dist[110000], T[110000], cnt, U[110000];
vector<pair<int, int>> x[110000], y[110000];
bool used[210000];
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a[i], &b[i]);
    x[a[i]].push_back(make_pair(b[i], i));
    x[b[i]].push_back(make_pair(a[i], i));
  }
  fill(dist, dist + n + 1, 999999);
  dist[1] = 0;
  queue<int> Q;
  Q.push(1);
  while (!Q.empty()) {
    int a1 = Q.front();
    Q.pop();
    for (pair<int, int> i : x[a1]) {
      if (dist[i.first] > dist[a1] + 1) {
        dist[i.first] = dist[a1] + 1;
        Q.push(i.first);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (pair<int, int> j : x[i]) {
      if (dist[i] < dist[j.first]) {
        y[i].push_back(j);
        T[j.first]++;
      }
    }
  }
  for (int i = 0; i < q; i++) {
    scanf("%d", &c);
    c--;
    queue<pair<int, int>> Q1;
    int ss = -1;
    if (dist[a[c]] < dist[b[c]])
      ss = b[c];
    if (dist[a[c]] > dist[b[c]])
      ss = a[c];
    if (ss >= 1 && U[ss] == 0 && used[c] == false) {
      Q1.push(make_pair(ss, c));
      while (!Q1.empty()) {
        int a1 = Q1.front().first, a2 = Q1.front().second;
        Q1.pop();
        if (U[a1] == 1 || used[a2] == true)
          continue;
        T[a1]--;
        used[a2] = true;
        if (T[a1] != 0)
          continue;
        cnt++;
        U[a1] = 1;
        for (pair<int, int> j : y[a1]) {
          if (U[j.first] == 0)
            Q1.push(j);
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, m, q, a, b, dist[110000];
vector<int> x[110000], y[110000];
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a, &b);
    x[a].push_back(b);
    x[b].push_back(a);
  }
  for (int i = 0; i < 110000; i++)
    dist[i] = 999999;
  dist[1] = 0;
  queue<int> Q;
  Q.push(0);
  while (!Q.empty()) {
    int a1 = Q.front();
    for (int i = 0; i < x[a1].size(); i++) {
      if (dist[x[a1][i]] > dist[a1] + 1) {
        dist[x[a1][i]] = dist[a1] + 1;
        Q.push(x[a1][i]);
      }
    }
  }
  return 0;
}
Problem p00550 (C++) — buggy submission, verdict: Time Limit Exceeded

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

vector<int> E[100000], pr[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000], cnt = 1;
bool b[200000], ok[100000];

void bfs(int u) {
  queue<int> que;
  que.push(u);
  while (!que.empty()) {
    int p = que.front();
    que.pop();
    for (int v : E[p]) {
      if (d[v] == d[p] + 1 && !ok[v]) {
        ok[v] = true;
        cnt++;
        que.push(v);
      }
    }
  }
}
int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  rep(i, m) {
    scanf("%d%d", &u[i], &v[i]);
    u[i]--;
    v[i]--;
    E[u[i]].push_back(v[i]);
    E[v[i]].push_back(u[i]);
  }
  queue<int> que;
  memset(d, -1, sizeof(d));
  d[0] = 0;
  que.push(0);
  while (!que.empty()) {
    int p = que.front();
    que.pop();
    for (int i : E[p]) {
      if (d[i] == -1) {
        d[i] = d[p] + 1;
        que.push(i);
      }
    }
  }
  rep(i, m) {
    if (d[u[i]] > d[v[i]])
      swap(u[i], v[i]);
  }
  rep(i, n) E[i].clear();
  rep(i, q) {
    scanf("%d", &r[i]);
    r[i]--;
    b[r[i]] = true;
  }
  ok[0] = true;
  rep(i, m) {
    if (!b[i]) {
      if (d[v[i]] - d[u[i]] == 1) {
        E[u[i]].push_back(v[i]);
      }
    }
  }
  bfs(0);
  for (int i = q - 1; i >= 0; i--) {
    ans[i] = n - cnt;
    if (d[v[r[i]]] - d[u[r[i]]] == 1 && !ok[v[r[i]]]) {
      E[u[r[i]]].push_back(v[r[i]]);
      if (ok[u[r[i]]]) {
        cnt++;
        ok[v[r[i]]] = true;
        bfs(v[r[i]]);
      }
    }
  }
  rep(i, q) printf("%d\\n", ans[i]);
}

Error: TLE

Fixed submission:

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

list<int> E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000], cnt = 1;
bool b[200000], ok[100000];

void bfs(int u) {
  queue<int> que;
  que.push(u);
  while (!que.empty()) {
    int p = que.front();
    que.pop();
    for (int v : E[p]) {
      if (d[v] == d[p] + 1 && !ok[v]) {
        ok[v] = true;
        cnt++;
        que.push(v);
      }
    }
  }
}
int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  rep(i, m) {
    scanf("%d%d", &u[i], &v[i]);
    u[i]--;
    v[i]--;
    E[u[i]].push_back(v[i]);
    E[v[i]].push_back(u[i]);
  }
  queue<int> que;
  memset(d, -1, sizeof(d));
  d[0] = 0;
  que.push(0);
  while (!que.empty()) {
    int p = que.front();
    que.pop();
    for (int i : E[p]) {
      if (d[i] == -1) {
        d[i] = d[p] + 1;
        que.push(i);
      }
    }
  }
  rep(i, m) {
    if (d[u[i]] > d[v[i]])
      swap(u[i], v[i]);
  }
  rep(i, n) E[i].clear();
  rep(i, q) {
    scanf("%d", &r[i]);
    r[i]--;
    b[r[i]] = true;
  }
  ok[0] = true;
  rep(i, m) {
    if (!b[i]) {
      if (d[v[i]] - d[u[i]] == 1) {
        E[u[i]].push_back(v[i]);
      }
    }
  }
  bfs(0);
  for (int i = q - 1; i >= 0; i--) {
    ans[i] = n - cnt;
    if (d[v[r[i]]] - d[u[r[i]]] == 1 && !ok[v[r[i]]]) {
      E[u[r[i]]].push_back(v[r[i]]);
      if (ok[u[r[i]]])
        bfs(u[r[i]]);
    }
  }
  rep(i, q) printf("%d\\n", ans[i]);
}
Problem p00552 (C++) — buggy submission, verdict: Runtime Error

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

int seg = 1;

class RAQ {
  vector<int> dat;

public:
  RAQ() : dat(seg * 2 - 1) {}
  void add(int a, int b, int x, int k = 0, int l = 0, int r = seg) {
    if (b <= l || r <= a)
      return;
    if (a <= l && r <= b) {
      dat[k] += x;
      return;
    }
    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);
  }
  int get(int i) {
    int s = 0;
    i += seg - 1;
    s += dat[i];
    while (i) {
      i = (i - 1) / 2;
      s += dat[i];
    }
    return s;
  }
};

signed main() {
  int n, q, x[200000], d[200000], l[200000];
  cin >> n >> q;
  while (seg < n)
    seg *= 2;
  vector<RAQ> ps(2);
  for (int i = 0; i < n; i++) {
    ps[0].add(i, i + 1, i);
    ps[1].add(i, i + 1, n - i - 1);
  }
  for (int i = 0; i < q; i++)
    cin >> x[i] >> d[i] >> l[i];
  for (int i = q - 1; i >= 0; i--) {
    int low = -1, up = n;
    while (up - low > 1) {
      int mid = (up + low) / 2;
      if (d[i] == 1) {
        if (ps[0].get(mid) < x[i])
          low = mid;
        else
          up = mid;
      } else {
        if (ps[1].get(mid) < n - x[i])
          up = mid;
        else
          low = mid;
      }
    }
    if (d[i] == 1)
      ps[1].add(0, up, l[i] * 2);
    else
      ps[0].add(up, seg, l[i] * 2);
  }
  for (int i = 0; i < n; i++)
    cout << (ps[0].get(i) + ps[1].get(i) - n + 1) / 2 << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int seg = 1;

class RAQ {
  vector<int> dat;

public:
  RAQ() : dat(seg * 2 - 1) {}
  void add(int a, int b, int x, int k = 0, int l = 0, int r = seg) {
    if (b <= l || r <= a)
      return;
    if (a <= l && r <= b) {
      dat[k] += x;
      return;
    }
    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);
  }
  int get(int i) {
    int s = 0;
    i += seg - 1;
    s += dat[i];
    while (i) {
      i = (i - 1) / 2;
      s += dat[i];
    }
    return s;
  }
};

signed main() {
  int n, q, x[100000], d[100000], l[100000];
  cin >> n >> q;
  while (seg < n)
    seg *= 2;
  vector<RAQ> ps(2);
  for (int i = 0; i < n; i++) {
    ps[0].add(i, i + 1, i);
    ps[1].add(i, i + 1, n - i - 1);
  }
  for (int i = 0; i < q; i++)
    cin >> x[i] >> d[i] >> l[i];
  for (int i = q - 1; i >= 0; i--) {
    int low = -1, up = n;
    while (up - low > 1) {
      int mid = (up + low) / 2;
      if (d[i] == 1) {
        if (ps[0].get(mid) < x[i])
          low = mid;
        else
          up = mid;
      } else {
        if (ps[1].get(mid) < n - x[i])
          up = mid;
        else
          low = mid;
      }
    }
    if (d[i] == 1)
      ps[1].add(0, up, l[i] * 2);
    else
      ps[0].add(up, seg, l[i] * 2);
  }
  for (int i = 0; i < n; i++)
    cout << (ps[0].get(i) + ps[1].get(i) - n + 1) / 2 << endl;
  return 0;
}