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

#include <stdio.h>
const int maxn = 100000 + 10;
const long long big = 2000000000;
struct card {
  int shu;
  char fu;
};
card L[maxn / 2 + 2], R[maxn / 2 + 2];
void zhenghe(card a[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  for (int i = 0; i < n1; i++)
    L[i] = a[left + i];
  for (int i = 0; i < n2; i++)
    R[i] = a[mid + i];
  L[n1].shu = R[n2].shu = big;
  int i = 0, j = 0;
  for (int k = left; k < right; k++) {
    if (L[i].shu <= R[j].shu)
      a[k] = L[i++];
    else
      a[k] = R[j++];
  }
}
void guibing(card a[], int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    guibing(a, mid, right);
    guibing(a, left, mid);
    zhenghe(a, left, mid, right);
  }
}
int fenge(card a[], int left, int right) {
  card x, t;
  x = a[right];
  int i = left - 1;
  for (int j = left; j < right; j++) {
    if (a[j].shu <= x.shu) {
      i++;
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }
  t = a[i + 1];
  a[i + 1] = a[right];
  a[right] = t;
  return i + 1;
}
void quicksort(card a[], int left, int right) {
  int q;
  if (left < right) {
    q = fenge(a, left, right);
    quicksort(a, left, q - 1);
    quicksort(a, q + 1, right);
  }
}
int main() {
  int n, huan, biao = 1;
  card a[maxn], b[maxn];
  char c[10];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s %d", c, &huan);
    a[i].shu = b[i].shu = huan;
    a[i].fu = b[i].fu = c[0];
  }
  quicksort(b, 0, n - 1);
  guibing(a, 0, n);
  for (int i = 0; i < n; i++) {
    if (a[i].fu != b[i].fu)
      biao = 0;
  }
  if (biao == 0)
    printf("Not stable\\n");
  else
    printf("Stable\\n");
  for (int i = 0; i < n; i++) {
    printf("%c %d\\n", b[i].fu, b[i].shu);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
#define mx 100000
#define P 2000000000

struct card {
  char su;
  int va;
};
struct card L[mx / 2 + 2], R[mx / 2 + 2];

void merg(struct card a[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for (int i = 0; i < n; i++)
    L[i] = a[left + i];
  for (int i = 0; i < n; i++)
    R[i] = a[mid + i];
  L[n1].va = R[n2].va = P;
  i = j = 0;
  for (int k = left; k, right; k++) {
    if (L[i].va <= R[j].va) {
      a[k] = L[i++];
    } else {
      a[k] = R[j++];
    }
  }
}

void mergesort(struct card a[], int n, int left, int right) {
  int mid;
  if (left + 1 < right) {
    mid = (left + right) / 2;
    mergesort(a, n, left, mid);
    mergesort(a, n, mid, right);
    merg(a, n, left, mid, right);
  }
}

int par(struct card a[], int n, int p, int r) {
  int i, j;
  struct card t, x;
  x = a[r];
  i = p - 1;
  for (int j = p; j < r; j++) {
    if (a[j].va <= x.va) {
      i++;
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }
  t = a[i + 1];
  a[i + 1] = a[r];
  a[r] = t;
  return i + 1;
}

void quik(struct card a[], int n, int p, int r) {
  int q;
  if (p < r) {
    q = par(a, n, p, r);
    quik(a, n, p, q - 1);
    quik(a, n, q + 1, r);
  }
}

int main() {
  int n, i, v;
  struct card a[mx], b[mx];
  char s[10];
  int sta = 1;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s %d", s, &v);
    a[i].su = b[i].su = s[0];
    a[i].va = b[i].va = v;
  }

  mergesort(a, n, 0, n);
  quik(a, n, 0, n - 1);

  for (i = 0; i < n; i++) {
    if (a[i].su != b[i].su) {
      sta = 0;
    }
  }
  if (sta == 1) {
    printf("Stable\\n");
  } else {
    printf("Not stable\\n");
  }
  for (i = 0; i < n; i++) {
    printf("%c %d\\n", b[i].su, b[i].va);
  }

  return 0;
}