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

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
struct Node {
  Node *l, *r;
  int st, ed, mi, lazy, val;
} *root, pool[404040];
int tot;
long long pre[202020];
inline void Build(Node *&now, int st, int ed) {
  now = &pool[++tot];
  now->st = st;
  now->ed = ed;
  now->lazy = 0;
  if (st == ed) {
    now->mi = 0;
    now->val = st;
    return;
  }
  int mid = ((st + ed) >> 1);
  Build(now->l, st, mid);
  Build(now->r, mid + 1, ed);
  now->mi = min(now->l->mi, now->r->mi);
}
inline void down(Node *now) {
  if (!now->lazy)
    return;
  now->l->lazy = now->lazy;
  now->r->lazy = now->lazy;
  now->l->mi = now->l->st - now->lazy;
  now->r->mi = now->r->st - now->lazy;
  now->l->val = now->r->val = now->lazy;
  now->lazy = 0;
}
inline void Cover(Node *now, int st, int ed, int val) {
  if (now->st > ed || now->ed < st)
    return;
  if (now->st >= st && now->ed <= ed) {
    now->lazy = val;
    now->mi = now->st - val;
    now->val = val;
    return;
  }
  down(now);
  Cover(now->l, st, ed, val);
  Cover(now->r, st, ed, val);
  now->mi = min(now->l->mi, now->r->mi);
}

inline int query(Node *now, int pos) {
  if (now->st >= pos && now->ed <= pos) {
    return now->val;
  }
  down(now);
  if (now->l->ed >= pos)
    return query(now->l, pos);
  return query(now->r, pos);
}
int a[201001], n, b[202020], c[202020], m;
long long ans, sum[202020] = {0};
int main() {
  scanf("%d%d", &n, &m);
  Build(root, 1, m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    if (a[i] == 1)
      Cover(root, a[i], b[i], -1000000);
    else
      Cover(root, a[i], b[i], query(root, a[i] - 1));
    if (root->mi + i >= 1000000)
      printf("-1\\n");
    else
      printf("%d\\n", i + root->mi);
  }
  return 0;
}
/*
2
1 2
99999 999
*/

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int n, f[5202020], siz[202020], a[202020], b[202020];
const int mod = 1e9 + 7;
long long sum = 0;

inline int getf(int x) {
  if (x == f[x])
    return x;
  return f[x] = getf(f[x]);
}
int m, aa, bb;
const int maxn = 10000000;
int h, w;
int c(int A, int B) { return A * (w + 1) + B; }
int main() {
  scanf("%d%d", &h, &w);
  for (int i = 2; i <= h + 1; i++) {
    scanf("%d%d", &a[i], &b[i]);
  }
  for (int i = 1; i <= w; i++)
    f[c(1, i)] = 0;
  for (int i = 2; i <= h + 1; i++) {
    int ans = maxn;
    if (a[i] > 1)
      f[c(i, 1)] = f[c(i - 1, 1)] + 1;
    else
      f[c(i, 1)] = maxn;
    ans = min(ans, f[c(i, 1)]);
    for (int j = 2; j <= w; j++) {
      f[c(i, j)] = f[c(i, j - 1)] + 1;
      if (j < a[i] || j > b[i])
        f[c(i, j)] = min(f[c(i - 1, j)] + 1, f[c(i, j)]);
      ans = min(ans, f[c(i, j)]);
    }
    if (ans == maxn) {
      printf("-1\\n");
    } else
      printf("%d\\n", ans);
  }
  return 0;
}
/*
5
6 14 15 7 12 16 5 4 11 9 3 10 8 2 13 1
4
1 2 3 4 5 6 7 8
*/
Problem p02575 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int INF = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<int> a(h), b(h);
  for (int i = 0; i < h; ++i) {
    cin >> a[i] >> b[i];
    a[i]--;
  }
  vector<int> f(w);
  vector<int> nxt(w);
  for (int i = 0; i < w; ++i) {
    f[i] = i;
    nxt[i] = i;
  }
  function<int(int)> find_next = [&](int i) {
    if (nxt[i] == i)
      return i;
    nxt[i] = find_next(nxt[i]);
    return nxt[i];
  };
  multiset<int> st;
  for (int i = 0; i < w; ++i)
    st.insert(f[i] - i);
  for (int i = 0; i < h; ++i) {
    int l = -1, r = w;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (f[find_next(m)] < a[i])
        l = m;
      else
        r = m;
    }
    if (r != w && f[find_next(r)] < b[i]) {
      int pos = r;
      while (pos < w) {
        pos = find_next(pos);
        if (f[pos] != w)
          st.erase(st.find(f[pos] - pos));
        if (pos + 1 < w && f[find_next(pos + 1)] < b[i]) {
          nxt[pos] = pos + 1;
          pos++;
        } else
          break;
      }
      f[pos] = b[i];
      if (f[pos] != w)
        st.insert(f[pos] - pos);
    }
    if (st.empty())
      cout << "-1\\n";
    else
      cout << *st.begin() + i + 1 << '\\n';
  }
  return 0;
}


Error: TLE

Fixed submission:

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

const int INF = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<int> a(h), b(h);
  for (int i = 0; i < h; ++i) {
    cin >> a[i] >> b[i];
    a[i]--;
  }
  vector<int> f(w);
  for (int i = 0; i < w; ++i)
    f[i] = i;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j)
      if (a[i] <= f[j] && f[j] < b[i])
        f[j] = b[i];
    int ans = INF;
    for (int j = 0; j < w; ++j)
      if (f[j] != w)
        ans = min(ans, f[j] - j + i + 1);
    if (ans == INF)
      cout << "-1\\n";
    else
      cout << ans << '\\n';
  }
  return 0;
}
Problem p02575 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using vi = vector<int>;
using ii = pair<int, int>;

int main() {
  cin.sync_with_stdio(false);
  cin.tie(NULL);

  int w, h;

  cin >> h >> w;
  set<ii> x, y;

  for (int i = 1; i <= w; i++) {
    y.insert(make_pair(0, i));
    x.insert(make_pair(i, i));
  }

  int a, b;
  for (int i = 1; i <= h; i++) {
    cin >> a >> b;
    ii st = make_pair(a, -1);
    ii end = make_pair(b, INT_MAX);
    for (auto it = x.lower_bound(st); it != x.upper_bound(end);
         it = x.lower_bound(st)) {
      int j = it->second;
      y.erase(make_pair(it->first - it->second, it->second));
      x.erase(it);

      if (x.lower_bound(st) == x.upper_bound(end)) {
        x.insert(make_pair(b == w ? INT_MAX : b + 1, j));
        y.insert(make_pair(b == w ? INT_MAX : b + 1 - j, j));
      }
    }

    int ans = y.begin()->first;
    cout << (ans == INT_MAX ? -1 : ans + i) << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

using vi = vector<int>;
using ii = pair<int, int>;

int main() {
  cin.sync_with_stdio(false);
  cin.tie(NULL);

  int w, h;

  cin >> h >> w;
  set<ii> x, y;

  for (int i = 1; i <= w; i++) {
    y.insert(make_pair(0, i));
    x.insert(make_pair(i, i));
  }

  int a, b;
  for (int i = 1; i <= h; i++) {
    cin >> a >> b;
    ii st = make_pair(a, -1);
    ii end = make_pair(b, INT_MAX);
    for (auto it = x.lower_bound(st); it != x.upper_bound(end);
         it = x.lower_bound(st)) {
      x.insert(make_pair(b == w ? INT_MAX : b + 1, it->second));
      y.erase(make_pair(it->first - it->second, it->second));
      y.insert(make_pair(b == w ? INT_MAX : b + 1 - it->second, it->second));
      x.erase(it);
    }

    int ans = y.begin()->first;
    cout << (ans == INT_MAX ? -1 : ans + i) << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
int n, m, dis[202020];
set<int> st;
multiset<int> sstt;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    st.insert(i);
    sstt.insert(0);
  }
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    set<int>::iterator it = st.lower_bound(a), it1;
    int mn = 1e9 + 1e5;
    while (it != st.end() && *it <= b) {
      int x = *it;
      mn = min(mn, dis[x] + b - x);
      it1 = it;
      it1++;
      st.erase(it);
      it = it1;
      sstt.erase(sstt.find(dis[x]));
      dis[x] = 1e9 + 1e5;
    }
    if (b != m && mn != 1e9 + 1e5) {
      dis[b] = mn;
      st.insert(b);
      sstt.insert(mn);
    }
    if (st.empty()) {
      cout << "-1\\n";
    } else {
      cout << *sstt.begin() + i + 1 << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, m, dis[101010];
set<int> st;
multiset<int> sstt;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    st.insert(i);
    sstt.insert(0);
  }
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    set<int>::iterator it = st.lower_bound(a), it1;
    int mn = 1e9 + 1e5;
    while (it != st.end() && *it <= b) {
      int x = *it;
      mn = min(mn, dis[x] + b - x);
      it1 = it;
      it1++;
      st.erase(it);
      it = it1;
      sstt.erase(sstt.find(dis[x]));
      dis[x] = 1e9 + 1e5;
    }
    if (b != m && mn != 1e9 + 1e5) {
      dis[b] = mn;
      st.insert(b);
      sstt.insert(mn);
    }
    if (st.empty()) {
      cout << "-1\\n";
    } else {
      cout << *sstt.begin() + i + 1 << endl;
    }
  }
  return 0;
}
Problem p02575 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// 始点を決めると、終点は必ず一意に決まる(なぜなら、下に行ける時は下に行き、いけない時は右に行くのが最善だから)
// すると、各高さについて、dp[高さ][終点]というように終点の数のデータで管理できる
// しかし、これではO(H * W)になってしまう、、、
// よく考えると、高さを+1するとき、下に障害物がある部分しか終点の情報が変わらないことが分かる
// 下に障害物がある時、終点をBi + 1に更新し、元の終点のデータを削除する
// こうすると、見るべきデータは下に障害物があるものだけであり、しかもそのデータは削除されるのでO(H
// + W)になるということが分かる
// データの管理をsetでおこなうと、全体の計算量はO((H + W) * log(H + W))

int main(void) {
  int h, w;
  cin >> h >> w;
  set<pair<int, int>> dest_and_start;
  multiset<int> value;
  vector<int> a(h);
  vector<int> b(h);
  for (int i = 0; i < h; i++)
    cin >> a[i] >> b[i];
  for (int i = 1; i <= w; i++) {
    dest_and_start.insert({i, i});
    value.insert(0);
  }
  for (int i = 0; i < h; i++) {
    int start = -1;
    auto obstacle = dest_and_start.lower_bound({a[i], -1});
    while (obstacle != dest_and_start.end() && (*obstacle).first <= b[i]) {
      if (b[i] != w && start < (*obstacle).second)
        start = (*obstacle).second;
      value.erase(value.find((*obstacle).first - (*obstacle).second));
      obstacle = dest_and_start.erase(obstacle);
    }
    if (start != -1) {
      dest_and_start.insert({b[i] + 1, start});
      value.insert(b[i] + 1 - start);
    }
    if (value.size() == 0)
      cout << -1 << endl;
    else
      cout << *value.begin() + i + 1 << endl;
  }
}

Error: TLE

Fixed submission:

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

// 始点を決めると、終点は必ず一意に決まる(なぜなら、下に行ける時は下に行き、いけない時は右に行くのが最善だから)
// すると、各高さについて、dp[高さ][終点]というように終点の数のデータで管理できる
// しかし、これではO(H * W)になってしまう、、、
// よく考えると、高さを+1するとき、下に障害物がある部分しか終点の情報が変わらないことが分かる
// 下に障害物がある時、終点をBi + 1に更新し、元の終点のデータを削除する
// こうすると、見るべきデータは下に障害物があるものだけであり、しかもそのデータは削除されるのでO(H
// + W)になるということが分かる
// データの管理をsetでおこなうと、全体の計算量はO((H + W) * log(H + W))

int main(void) {
  int h, w;
  cin >> h >> w;
  set<pair<int, int>> dest_and_start;
  vector<int> a(h);
  vector<int> b(h);
  for (int i = 0; i < h; i++)
    cin >> a[i] >> b[i];
  // 番兵をいれておく
  dest_and_start.insert({-1, -1});
  for (int i = 1; i <= w; i++)
    dest_and_start.insert({i, i});
  for (int i = 0; i < h; i++) {
    auto obstacle = dest_and_start.lower_bound({a[i], -1});
    while (obstacle != dest_and_start.end() && (*obstacle).first <= b[i]) {
      if (b[i] != w)
        dest_and_start.insert({b[i] + 1, (*obstacle).second});
      obstacle = dest_and_start.erase(obstacle);
    }
    auto itr = dest_and_start.end();
    itr--;
    int start = -1;
    int end = -1;
    int ans = 1e9;
    while (dest_and_start.size() && itr != dest_and_start.begin()) {
      ans = min(ans, (*itr).first - (*itr).second + i + 1);
      if ((*itr).first != end) {
        end = (*itr).first;
        start = (*itr).second;
        itr--;
      } else if ((*itr).second < start)
        itr = dest_and_start.erase(itr);
    }
    if (dest_and_start.size() == 1)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
}
Problem p02575 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
  u64 H, W;
  cin >> H >> W;

  map<u64, u64> ranges;
  multiset<u64> vals;

  for (u64 j = 0; j < W; j++) {
    ranges[j] = j;
    vals.insert(0);
  }

  for (u64 i = 0; i < H; i++) {
    u64 A, B;
    cin >> A >> B;
    A--;
    B--;

    auto lp = ranges.lower_bound(A);
    s64 max_r = -1;

    while (lp != ranges.end() && lp->first <= B + 1) {
      max_r = max(max_r, (s64)lp->second);
      u64 dist = lp->first - lp->second;

      vals.erase(vals.find(dist));
      ranges.erase(lp++);
    }

    if (max_r != -1 && B < W - 1) {
      vals.insert(B - max_r + 1);
      ranges[B + 1] = max_r;
    }

    if (vals.empty()) {
      cout << -1 << endl;
    } else {
      cout << *vals.begin() + i + 1 << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
  u64 H, W;
  cin >> H >> W;

  vector<map<u64, u64>> costs(2, map<u64, u64>());

  for (u64 j = 0; j < W; j++) {
    costs[0][j] = 0;
  }

  for (u64 i = 0; i < H; i++) {
    bool cur = i % 2;
    bool nxt = !cur;

    u64 A, B;
    cin >> A >> B;
    A--;
    B--;

    u64 cost_i = UINT64_MAX;

    for (auto &p : costs[cur]) {
      auto cur_point = p.first;
      auto cur_cost = p.second;

      if (cur_point < A || cur_point > B) {
        costs[nxt][cur_point] = cur_cost + 1;
        cost_i = min(cost_i, costs[nxt][cur_point]);
      } else if (B + 1 < W) {
        u64 nxt_cost = cur_cost + B + 1 - cur_point + 1;
        if (costs[nxt][B + 1] == 0) {
          costs[nxt][B + 1] = nxt_cost;
        } else {
          costs[nxt][B + 1] = min(costs[nxt][B + 1], nxt_cost);
        }
        cost_i = min(cost_i, costs[nxt][B + 1]);
      }
    }

    if (cost_i == UINT64_MAX) {
      cout << -1 << endl;
    } else {
      cout << cost_i << endl;
    }

    costs[cur].clear();
  }

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

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

#define REP(i, p, n) for (ll i = p; i < ll(n); ++i)
#define rep(i, n) REP(i, 0, n)

using ll = long long;
using pll = pair<ll, ll>;

const ll INF = 1LL << 30;

int main() {
  ll H, W;
  cin >> H >> W;

  set<pll> nodes;
  multiset<ll> costs;

  rep(i, W) {
    nodes.emplace(i, i);
    costs.emplace(0);
  }

  rep(y, H) {
    ll a, b;
    cin >> a >> b, --a, --b;

    ll newSrc = -1;
    const auto newDst = b + 1;

    // ひとつだけ残して削除する (TODO: 範囲削除)
    {
      auto it = nodes.lower_bound(pll(a, 0));
      while (it != nodes.end()) {
        const auto src = it->second, dst = it->first;
        if (b < dst) {
          break;
        }

        // nodesとcostsは同期してるので必ずdst-srcな値があるはず
        costs.erase(costs.find(dst - src));
        it = nodes.erase(it);

        newSrc = max(newSrc, src);
      }
    }

    if (newSrc != -1 && newDst != W) {
      nodes.emplace(newDst, newSrc);
      costs.emplace(newDst - newSrc);
    }

    const auto cost = costs.begin() != costs.end() ? *costs.begin() : W;
    cout << (cost != W ? cost + y + 1 : -1) << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

#define REP(i, p, n) for (ll i = p; i < ll(n); ++i)
#define rep(i, n) REP(i, 0, n)

using ll = long long;
using pll = pair<ll, ll>;

const ll INF = 1LL << 30;

int main() {
  ll H, W;
  cin >> H >> W;

  set<pll> nodes;
  rep(i, W) { nodes.emplace(i, i); }

  rep(y, H) {
    ll a, b;
    cin >> a >> b, --a, --b;

    ll ans = INF;

    pll replacer(-1, b + 1);

    auto it = nodes.begin(), end = nodes.end();

    while (it != end) {
      const auto src = it->first;
      const auto dst = it->second;

      if (a <= dst && dst <= b) {
        replacer.first = max(replacer.first, src);
        it = nodes.erase(it);
      } else {
        ans = min(ans, (dst - src) + (y + 1));
        ++it;
      }
    }

    if (replacer.first != -1 && replacer.second != W) {
      nodes.emplace(replacer);
      ans = min(ans, (replacer.second - replacer.first) + (y + 1));
    }

    cout << (ans != INF ? ans : -1) << endl;
  }

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

#include <algorithm>
#include <climits>
#include <iostream>
#include <set>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
  int H, W;
  cin >> H >> W;

  set<pair<int, int>> s;
  multiset<int> m;
  for (int i = 0; i < W; ++i) {
    s.insert({i, i});
    m.insert(0);
  }

  for (int i = 1; i <= H; ++i) {
    int A, B;
    cin >> A >> B;
    --A;
    --B;

    if (B == W - 1) {
      auto it = s.lower_bound({A, -1});
      for (; it != s.end() && it->first <= B;) {
        m.erase(m.find(it->first - it->second));
        s.erase(it++);
      }
    } else {
      int last_start_point = -1;
      auto it = s.lower_bound({A, -1});
      for (; it != s.end() && it->first <= B;) {
        last_start_point = it->second;
        m.erase(m.find(it->first - it->second));
        s.erase(it++);
      }
      if (last_start_point != -1 && (it == s.end() || it->first != B + 1)) {
        m.insert(B + 1 - last_start_point);
        s.insert({B + 1, last_start_point});
      }
    }

    cout << (m.empty() ? -1 : (*m.begin() + i)) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
  ll H, W;
  cin >> H >> W;

  vector<ll> grid(W, 0);
  vector<ll> distance(W, 0);
  for (int i = 0; i < H; ++i) {
    ll A, B;
    cin >> A >> B;
    grid.assign(W, 0);
    for (int j = A - 1; j <= B - 1; ++j) {
      grid[j] = 1;
    }

    int last = 0;
    for (int j = last; j < W; ++j) {
      if (grid[j] == 0 && distance[j] != LLONG_MAX) {
        ++distance[j];
      } else if (j - 1 >= 0 && distance[j - 1] != LLONG_MAX) {
        distance[j] = distance[j - 1] + 1;
      } else {
        distance[j] = LLONG_MAX;
        last = j + 1;
      }
    }

    ll d = *min_element(distance.begin(), distance.end());
    if (d == LLONG_MAX) {
      cout << -1 << endl;
    } else {
      cout << d << endl;
    }
  }

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

int H, W;
int l, r;
set<pair<int, int>> s;
multiset<int> ms;

int main() {
  scanf("%d%d", &H, &W);
  for (int i = 1; i <= W; ++i)
    s.insert(make_pair(i, i)), ms.insert(0);

  for (int i = 1; i <= H; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);

    set<pair<int, int>>::iterator it;
    int mx = -1, xx = 0;
    vector<pair<int, int>> v;
    for (it = s.lower_bound(make_pair(l, 0)); it != s.end() && (*it).first <= r;
         it++) {
      // cerr << (*it).first << " " << (*it).second << endl;
      mx = max(mx, (*it).second);
      int num = (*it).first - (*it).second;
      ms.erase(ms.find(num));
      v.push_back(*it);
    }
    int si = v.size();
    for (int j = 0; j < si; ++j) {
      pair<int, int> a = v[j];
      s.erase(s.find(a));
    }
    if (mx != -1 && r + 1 <= W) {
      ms.insert(r + 1 - mx);
      s.insert(make_pair(r + 1, mx));
    }
    if (ms.size() > 0)
      printf("%d\\n", *ms.begin() + i);
    else
      printf("-1\\n");
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

int H, W;
int l, r;
set<pair<int, int>> s[200005];
multiset<int> ms;

int main() {
  scanf("%d%d", &H, &W);
  for (int i = 1; i <= W; ++i)
    s[0].insert(make_pair(i, i)), ms.insert(0);

  for (int i = 1; i <= H; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);

    set<pair<int, int>>::iterator it;
    int mx = -1, xx = 0;
    for (it = s[i - 1].begin(); it != s[i - 1].end(); it++) {
      if ((*it).first >= l && (*it).first <= r) {
        mx = max(mx, (*it).second);
        int num = (*it).first - (*it).second;
        ms.erase(ms.find(num));
      } else
        s[i].insert(*it);
    }
    if (mx != -1 && r + 1 <= W) {
      ms.insert(r + 1 - mx);
      s[i].insert(make_pair(r + 1, mx));
    }
    if (ms.size() > 0)
      printf("%d\\n", *ms.begin() + i);
    else
      printf("-1\\n");
  }

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

#include <stdio.h>

int main() {
  int num, max, time, a;
  scanf("%d%d%d", &num, &max, &time);
  if (num % max == 0)
    a = num / max;
  else
    a = num / max + 1;
  printf("%d", a * time);
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int num, max, time, a;
  scanf("%d%d%d", num, max, time);
  a = num / max + 1;
  printf("%d", a * time);
  return 0;
}
Problem p02576 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, x, t, c = 0;
  cin >> n >> x >> t;
  while (n > 0) {
    n -= x;
    c++;
  }
  cout << c * t << endl;
  return 0;
}

Error: 12

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, x, t, c = 0;
  cin >> n >> x >> t;
  while (n > 0) {
    n -= x;
    c++;
  }
  return c * t;
}
Problem p02576 (C++) — buggy submission, verdict: Runtime Error


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, x, t;
  cin >> n >> x >> t;
  if (n % x == 0)
    cout << (n / x) * t;
  else {
    cout << (n / x + 1) * t;
  }
  return 0;
}


Error: 12

Fixed submission:


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, x, t;
  cin >> n >> x >> t;
  if (n % x == 0)
    return (n / x) * t;
  else {
    return (n / x + 1) * t;
  }
}
Problem p02576 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  int ans = 0;
  ans += n / x * t + !!(n - n / x * x) * t;
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  cout << (n / (x - 1) * t + t) << endl;
}
Problem p02576 (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 repr(i, x, n) for (int i = x; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main() {
  int n, x, t;
  bool a = false;
  cin >> n >> x >> t;
  if (n % x == 0) {
    cout << n / x * t << endl;
    goto owari;
  }

  cout << (n / x + 1) * t << endl;
owari:
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, x, n) for (int i = x; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main() {
  int n, x, t;
  bool a = false;
  cin >> n >> x >> t;
  if (n % x == 0) {
    cout << n / x * t << endl;
    abort();
  }

  cout << (n / x + 1) * t << endl;
  return 0;
}
Problem p02576 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  float N, X, T;
  cin >> N >> X >> T;
  int result = ceil(N / X) * T;
  cout << result;
  return 0;
}

Error: 6

Fixed submission:

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

int main() {
  int N, X, T;
  cin >> N >> X >> T;
  return ceil(N / X) * T;
}
Problem p02576 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
using namespace std;
int main() {
  long long int n, x, t;
  scanf("%lld %lld %lld", &n, &x, &t);
  long long int p, ans;
  p = n / x;

  if (n % x > 0) {
    p++;
  }

  ans = p * t;
  printf("%lld", ans);
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
using namespace std;
int main() {
  long long int n, x, t;
  scanf("%lld %lld %lld", n, x, t);
  long long int p, ans;
  p = n / x;
  ans = p * t;
  printf("%lld", ans);
  return 0;
}