Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)

#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)

#define _all(arg) begin(arg), end(arg)
#define uniq(arg) sort(_all(arg)), (arg).erase(unique(_all(arg)), end(arg))
#define getidx(ary, key) lower_bound(_all(ary), key) - begin(ary)
#define clr(a, b) memset((a), (b), sizeof(a))
#define bit(n) (1LL << (n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
  return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
  return (b < a) ? (a = b, 1) : 0;
}

using ll = long long;
using R = long double;
const R EPS = 1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); }
inline R sq(R x) { return sqrt(max<R>(x, 0.0)); }

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

// Problem Specific Parameter:

struct Segment_tree {
  using T = ll;

  int n;
  vector<T> data;
  const T out = (1LL << 31) - 1;

  inline T vmerge(T l, T r) { return min(l, r); }

  Segment_tree(int n) : n(n) { data.assign(2 * n, out); }

  void update(int p, T x) { // set value at position p
    for (data[p += n] = x; p > 1; p >>= 1)
      data[p >> 1] = vmerge(data[p], data[p ^ 1]);
  }

  T query(int l, int r) { // sum on interval [l, r)
    T resl = out, resr = out;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1)
        resl = vmerge(data[l++], resl);
      if (r & 1)
        resr = vmerge(resr, data[--r]);
    }
    return vmerge(resl, resr);
  }
};

int main(void) {
  int n, q;
  cin >> n >> q;

  Segment_tree rmq(n);

  rep(loop, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com)
      cout << rmq.query(x, y + 1) << endl;
    else
      rmq.update(x, y);
  }
  return 0;
}

Error: 0
4


Fixed submission:

#include <bits/stdc++.h>

#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)

#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)

#define _all(arg) begin(arg), end(arg)
#define uniq(arg) sort(_all(arg)), (arg).erase(unique(_all(arg)), end(arg))
#define getidx(ary, key) lower_bound(_all(ary), key) - begin(ary)
#define clr(a, b) memset((a), (b), sizeof(a))
#define bit(n) (1LL << (n))
#define popcount(n) (__builtin_popcountll(n))

template <class T> bool chmax(T &a, const T &b) {
  return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
  return (b < a) ? (a = b, 1) : 0;
}

using namespace std;

struct segtree {
  int n, out;
  vector<int> data, lazy;

  segtree(int _n, int _out) {
    n = 1 << (32 - __builtin_clz(_n));
    cerr << n << endl;
    out = _out;
    data.assign(2 * n - 1, out);
    lazy.assign(2 * n - 1, out);
  }

  inline int vmerge(int a, int b) { return min(a, b); }

  inline void lazy_eval(int k, int l, int r) {
    if (r - l <= 1)
      return;
    if (lazy[k] == out)
      return;
    rep(i, 2) data[2 * k + 1 + i] = lazy[k], lazy[2 * k + 1 + i] = lazy[k];
    lazy[k] = out;
  }

  int update(int a, int b, int x, int k, int l, int r) {
    if (b <= l || r <= a)
      return data[k];
    if (a <= l && r <= b)
      return lazy[k] = x, data[k] = x;
    lazy_eval(k, l, r);
    const int m = (l + r) / 2;
    return data[k] = vmerge(update(a, b, x, 2 * k + 1, l, m),
                            update(a, b, x, 2 * k + 2, m, r));
  }

  int query(int a, int b, int k, int l, int r) {
    if (b <= l || r <= a)
      return out;
    if (a <= l && r <= b)
      return data[k];
    lazy_eval(k, l, r);
    const int m = (l + r) / 2;
    return vmerge(query(a, b, 2 * k + 1, l, m), query(a, b, 2 * k + 2, m, r));
  }
};

const int inf = -1 + (1 << 30) + (1 << 30);

int main(void) {
  int n, q;
  cin >> n >> q;
  segtree rmq(n, inf);
  rep(loop, q) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t)
      cout << rmq.query(x, y + 1, 0, 0, rmq.n) << endl;
    else
      rmq.update(x, x + 1, y, 0, 0, rmq.n);
  }
  return 0;
}