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

#include <bits/stdc++.h>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const long INF = pow(2, 31) - 1;
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

const long P_SIZE = 301;
const long MAX_N = 100004;
long packet[401];
long arr[MAX_N];

long find(long x, long y) {
  long res = INF;
  if (floor(x / P_SIZE) ==
      floor(y / P_SIZE)) { // 1???????????±??????????????¨??§?????????
    FOR(i, x, y + 1) { res = min(res, arr[i]); }
    return res;
  }
  long pb = x / P_SIZE +
            1; //???????????????????????±??????????¬?????????±????????????
  long pd =
      y / P_SIZE - 1; //??????????????¨?????????????????????????????±??????
  FOR(i, x, min(pb * P_SIZE, y + 1)) {
    res = min(res, arr[i]); //????????????
  }
  if (pb <= pd)
    FOR(i, pb, pd + 1) {
      // cout<<"!2"<<endl;
      res = min(res, packet[i]); //?????±????????????????????????
    }
  FOR(i, max(pd * P_SIZE, x), y + 1) {
    // cout<<"!3"<<endl;
    res = min(res, arr[i]); //????????????
  }
  return res;
}

void update(long x, long y) {
  arr[x] = y;
  long pb = floor(x / P_SIZE); //?????????????±????????????±??????
  packet[pb] = INF;
  FOR(i, pb * P_SIZE, (pb + 1) * P_SIZE) {
    packet[pb] = min(packet[pb], arr[i]);
  }
}

int main() {
  int N, Q;
  cin >> N >> Q;
  fill(packet, packet + 401, INF);
  fill(arr, arr + MAX_N, INF);

  REP(i, Q) {
    long c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      update(x, y);
    } else {
      cout << find(x, y) << endl;
    }
  }
  // REP(i,SZ(res))cout<<res[i]<<endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const long INF = pow(2, 31) - 1;
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

const int P_SIZE = 300;
const int MAX_N = 100004;
long packet[401];
long arr[MAX_N];

long find(long x, long y) {
  long res = INF;
  if (x / P_SIZE == y / P_SIZE) { // 1???????????±??????????????¨??§?????????
    FOR(i, x, y + 1) { res = min(res, arr[i]); }
    return res;
  }
  long pb = x / P_SIZE +
            1; //???????????????????????±??????????¬?????????±????????????
  long pd =
      y / P_SIZE - 1; //??????????????¨?????????????????????????????±??????
  FOR(i, x, pb * P_SIZE) {
    res = min(res, arr[i]); //????????????
  }
  FOR(i, pb, pd + 1) {
    // cout<<"!2"<<endl;
    res = min(res, packet[i]); //?????±????????????????????????
  }
  FOR(i, pd * P_SIZE, y + 1) {
    // cout<<"!3"<<endl;
    res = min(res, arr[i]); //????????????
  }
  return res;
}

void update(long x, long y) {
  arr[x] = y;
  long pb = x / P_SIZE;
  packet[pb] = INF;
  FOR(i, pb * P_SIZE, (pb + 1) * P_SIZE) {
    packet[pb] = min(packet[pb], arr[i]);
  }
}

int main() {
  int N, Q;
  cin >> N >> Q;
  fill(packet, packet + 401, INF);
  fill(arr, arr + MAX_N, INF);
  vector<LL> res;
  REP(i, Q) {
    long c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      update(x, y);
    } else {
      cout << res[i] << endl;
    }
  }
  // REP(i,SZ(res))cout<<res[i]<<endl;
  return 0;
}