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

#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define pb push_back
using namespace std;

const int N = 200005;
ll n, m, t, a[N], k, l[N], r[N], ans, tong;
ll b[N];
vector<pll> kq;
string s;
priority_queue<pii, vector<pii>, greater<pii>> pr;
void sol() {
  cin >> n >> s;
  s = " " + s;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    l[i] = i - 1;
    r[i] = i + 1;
  }
  for (int i = 2; i <= n; i++) {
    if (s[i - 1] != s[i]) {
      k = abs(a[i] - a[i - 1]);
      pii u;
      u.fi = k;
      u.se.fi = i - 1;
      u.se.se = i;
      pr.push(u);
    }
  }
  while (!pr.empty()) {
    pii u = pr.top();
    pr.pop();
    ll x = u.se.fi, y = u.se.se;
    if (b[x] == 1 || b[y] == 1)
      continue;
    b[x] = 1;
    b[y] = 1;

    l[r[y]] = l[x];
    r[l[x]] = r[y];
    kq.pb({x, y});
    if (l[x] > 0 && r[y] <= n && s[l[x]] != s[r[y]]) {
      pii v;
      v.fi = abs(a[l[x]] - a[r[y]]);
      v.se.fi = l[x];
      v.se.se = r[y];
      pr.push(v);
    }
  }
  cout << kq.size() << '\\n';
  for (pll u : kq)
    cout << u.fi << " " << u.se << '\\n';
}
ll random(ll minn, ll maxn) { return minn + rand() % (maxn + 1 - minn); }
priority_queue<ll> st;
ll uoc(ll a, ll b) {
  while (b != 0) {
    ll r = a % b;
    a = b;
    b = r;
  }
  return a;
}
map<ll, ll> mp;
void test() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    l[i] = a[i];
    r[i] = a[i];
  }

  for (int i = 2; i <= n; i++) {
    l[i] = l[i - 1] ^ a[i];
  }
  for (int i = n - 1; i > 0; i--) {
    r[i] = r[i + 1] ^ a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1)
      cout << r[i + 1];
    else if (i == n)
      cout << l[i - 1];
    else
      cout << (r[i + 1] ^ l[i - 1]);
    cout << " ";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test();
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define pb push_back
using namespace std;

const int N = 100005;
ll n, m, t, a[N], k, l[N], r[N], ans, tong;
ll b[N];
vector<pll> kq;
string s;
priority_queue<pii, vector<pii>, greater<pii>> pr;
void sol() {
  cin >> n >> s;
  s = " " + s;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    l[i] = i - 1;
    r[i] = i + 1;
  }
  for (int i = 2; i <= n; i++) {
    if (s[i - 1] != s[i]) {
      k = abs(a[i] - a[i - 1]);
      pii u;
      u.fi = k;
      u.se.fi = i - 1;
      u.se.se = i;
      pr.push(u);
    }
  }
  while (!pr.empty()) {
    pii u = pr.top();
    pr.pop();
    ll x = u.se.fi, y = u.se.se;
    if (b[x] == 1 || b[y] == 1)
      continue;
    b[x] = 1;
    b[y] = 1;

    l[r[y]] = l[x];
    r[l[x]] = r[y];
    kq.pb({x, y});
    if (l[x] > 0 && r[y] <= n && s[l[x]] != s[r[y]]) {
      pii v;
      v.fi = abs(a[l[x]] - a[r[y]]);
      v.se.fi = l[x];
      v.se.se = r[y];
      pr.push(v);
    }
  }
  cout << kq.size() << '\\n';
  for (pll u : kq)
    cout << u.fi << " " << u.se << '\\n';
}
ll random(ll minn, ll maxn) { return minn + rand() % (maxn + 1 - minn); }
priority_queue<ll> st;
ll uoc(ll a, ll b) {
  while (b != 0) {
    ll r = a % b;
    a = b;
    b = r;
  }
  return a;
}
map<ll, ll> mp;
void test() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    l[i] = a[i];
    r[i] = a[i];
  }
  for (int i = 2; i <= n; i++) {
    l[i] = l[i - 1] ^ a[i];
  }
  for (int i = n - 1; i > 0; i--) {
    r[i] = r[i + 1] ^ a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1)
      cout << r[i + 1];
    else if (i == n)
      cout << l[i - 1];
    else
      cout << (r[i + 1] ^ l[i - 1]);
    cout << " ";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test();
}