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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x)                                                         \\
  sort(all((x)));                                                              \\
  (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 2e5 + 42;
ll n, m;
struct ppolls {
  pair<ll, ll> mns;
  pair<ll, ll> mxs;
  pair<ll, ll> mnd;
  pair<ll, ll> mxd;
};
ppolls emp;
ppolls comb(ppolls a, ppolls b) {
  ppolls res;
  res.mns = (a.mns.fi + a.mns.se < b.mns.fi + b.mns.se ? a.mns : b.mns);
  res.mxs = (a.mxs.fi + a.mxs.se > b.mxs.fi + b.mxs.se ? a.mxs : b.mxs);
  res.mnd = (a.mnd.fi - a.mnd.se < b.mnd.fi - b.mnd.se ? a.mnd : b.mnd);
  res.mxd = (a.mxd.fi - a.mxd.se > b.mxd.fi - b.mxd.se ? a.mxd : b.mxd);
  return res;
}
ppolls st[4 * N];
vector<pair<ll, ll>> a;
void build(ll v, ll tl, ll tr) {
  if (tl == tr) {
    st[v].mns = a[tl];
    st[v].mxs = a[tl];
    st[v].mnd = a[tl];
    st[v].mxd = a[tl];
    return;
  }
  ll tm = ((tl + tr) >> 1);
  build((v << 1), tl, tm);
  build((v << 1) + 1, tm + 1, tr);
  st[v] = comb(st[(v << 1)], st[(v << 1) + 1]);
}
ppolls get(ll v, ll tl, ll tr, ll l, ll r) {
  if (l > r) {
    ppolls emp;
    emp.mns = mp(1e9 + 42, 1e9 + 42);
    emp.mxs = mp(-1e9 + 42, -1e9 + 42);
    emp.mnd = mp(1e9 + 42, 0);
    emp.mxd = mp(0, 1e9 + 42);
    return emp;
  }
  if (l == tl && r == tr)
    return st[v];
  ll tm = ((tl + tr) >> 1);
  return comb(get((v << 1), tl, tm, l, min(r, tm)),
              get((v << 1) + 1, tm + 1, tr, max(l, tm + 1), r));
}
void upd(ll v, ll tl, ll tr, ll pos, pair<ll, ll> new_v) {
  if (tl == tr) {
    st[v].mns = new_v;
    st[v].mxs = new_v;
    st[v].mnd = new_v;
    st[v].mxd = new_v;
    return;
  }
  ll tm = ((tl + tr) >> 1);
  if (pos <= tm)
    upd((v << 1), tl, tm, pos, new_v);
  else
    upd((v << 1) + 1, tm + 1, tr, pos, new_v);
  st[v] = comb(st[(v << 1)], st[(v << 1) + 1]);
}
int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n;

  // yay

  a.resize(n);

  for (ll i = 0; i < n; i++)
    cin >> a[i].fi >> a[i].se;

  build(1, 0, n - 1);

  auto ans = st[1];

  cout << max(ans.mxs.fi + ans.mxs.se - (ans.mns.fi + ans.mns.se),
              ans.mxd.fi - ans.mxd.se - (ans.mnd.fi - ans.mnd.se))
       << endl;

  return 0;
}
/*

*/


Error: 0

Fixed submission:

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x)                                                         \\
  sort(all((x)));                                                              \\
  (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 1e5 + 42;
ll n, m;
struct ppolls {
  pair<ll, ll> mns;
  pair<ll, ll> mxs;
  pair<ll, ll> mnd;
  pair<ll, ll> mxd;
};
ppolls emp;
ppolls comb(ppolls a, ppolls b) {
  ppolls res;
  res.mns = (a.mns.fi + a.mns.se < b.mns.fi + b.mns.se ? a.mns : b.mns);
  res.mxs = (a.mxs.fi + a.mxs.se > b.mxs.fi + b.mxs.se ? a.mxs : b.mxs);
  res.mnd = (a.mnd.fi - a.mnd.se < b.mnd.fi - b.mnd.se ? a.mnd : b.mnd);
  res.mxd = (a.mxd.fi - a.mxd.se > b.mxd.fi - b.mxd.se ? a.mxd : b.mxd);
  return res;
}
ppolls st[4 * N];
vector<pair<ll, ll>> a;
void build(ll v, ll tl, ll tr) {
  if (tl == tr) {
    st[v].mns = a[tl];
    st[v].mxs = a[tl];
    st[v].mnd = a[tl];
    st[v].mxd = a[tl];
    return;
  }
  ll tm = ((tl + tr) >> 1);
  build((v << 1), tl, tm);
  build((v << 1) + 1, tm + 1, tr);
  st[v] = comb(st[(v << 1)], st[(v << 1) + 1]);
}
ppolls get(ll v, ll tl, ll tr, ll l, ll r) {
  if (l > r) {
    ppolls emp;
    emp.mns = mp(1e9 + 42, 1e9 + 42);
    emp.mxs = mp(-1e9 + 42, -1e9 + 42);
    emp.mnd = mp(1e9 + 42, 0);
    emp.mxd = mp(0, 1e9 + 42);
    return emp;
  }
  if (l == tl && r == tr)
    return st[v];
  ll tm = ((tl + tr) >> 1);
  return comb(get((v << 1), tl, tm, l, min(r, tm)),
              get((v << 1) + 1, tm + 1, tr, max(l, tm + 1), r));
}
void upd(ll v, ll tl, ll tr, ll pos, pair<ll, ll> new_v) {
  if (tl == tr) {
    st[v].mns = new_v;
    st[v].mxs = new_v;
    st[v].mnd = new_v;
    st[v].mxd = new_v;
    return;
  }
  ll tm = ((tl + tr) >> 1);
  if (pos <= tm)
    upd((v << 1), tl, tm, pos, new_v);
  else
    upd((v << 1) + 1, tm + 1, tr, pos, new_v);
  st[v] = comb(st[(v << 1)], st[(v << 1) + 1]);
}
int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n;

  // yay

  a.resize(n);

  for (ll i = 0; i < n; i++)
    cin >> a[i].fi >> a[i].se;

  build(1, 0, n - 1);

  auto ans = st[1];

  cout << max(ans.mxs.fi + ans.mxs.se - (ans.mns.fi + ans.mns.se),
              ans.mxd.fi - ans.mxd.se - (ans.mnd.fi - ans.mnd.se))
       << endl;

  return 0;
}
/*

*/