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

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 998244353;
long long INF = 1000000000000000; // 10^15
typedef long long ll;
typedef unsigned long long ull;

ll powMod(ll x, ll n, ll mod) {
  if (n == 0)
    return 1;
  ll t = powMod(x, n / 2, mod);
  t = t * t % mod;
  if (n & 1)
    return t * x % mod;
  return t;
}

int main(void) {

  int n, k, c;
  string s;
  int m = 0;
  int w = 0;

  int p, q, u, v;

  int f = -200100;

  cin >> n >> k >> c;
  cin >> s;

  vector<int> a(n + 10, 0), g(n + 10), b(n + 10, 0), xx(n + 10);
  vector<bool> r(n + 10, false);

  for (int i = 1; i <= s.size(); i++) {
    if (m > 0) {
      a[i] = a[i - 1];
      m--;
    } else if (s[i - 1] == 'x') {
      a[i] = a[i - 1];
    } else if (s[i - 1] == 'o') {
      r[i] = true;
      a[i] = a[i - 1] + 1;
      m = c;
    }
  }

  for (int i = 1; i <= n; i++) {
    xx[i] = w;
    if (r[i]) {
      w = i;
      xx[i] = w;
    }
  }

  m = 0;
  for (int i = s.size(); i >= 1; i--) {
    if (m > 0) {
      b[i] = b[i + 1];
      m--;
    } else if (s[i - 1] == 'x') {
      b[i] = b[i + 1];
    } else if (s[i - 1] == 'o') {
      b[i] = b[i + 1] + 1;
      m = c;
    }
  }

  f = 0;
  for (int i = 1; i <= n; i++) {
    g[i] = f;
    if (s[i - 1] == 'o')
      f = i;
  }

  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == 'x')
      continue;
    if (g[i] <= 0)
      p = 0;
    else
      p = a[g[i]];
    int e = xx[g[i]];
    if (e == 0)
      e = i + 1;
    else
      e = max(e + c + 1, i + 1);
    // cout << e << endl;
    if (e > n)
      q = 0;
    else
      q = b[e];
    // cout << "e = " << e << endl;
    // cout << i << " " << p << " " << q << " ";
    if (i - c - 1 <= 0)
      u = 0;
    else
      u = a[i - c - 1];
    if (i + c + 1 > n)
      v = 0;
    else
      v = b[i + c + 1];
    // cout << u + v << endl;
    if (p + q < k && u + v + 1 >= k)
      cout << i << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 998244353;
long long INF = 1000000000000000; // 10^15
typedef long long ll;
typedef unsigned long long ull;

ll powMod(ll x, ll n, ll mod) {
  if (n == 0)
    return 1;
  ll t = powMod(x, n / 2, mod);
  t = t * t % mod;
  if (n & 1)
    return t * x % mod;
  return t;
}

int main(void) {

  int n, k, c;
  string s;
  int m = 0;
  int w = 0;

  int p, q, u, v;

  int f = -200100;

  cin >> n >> k >> c;
  cin >> s;

  vector<int> a(n + 10, 0), g(n + 10), b(n + 10, 0), h(n + 10), xx(n + 10);
  vector<bool> r(n + 10, false);

  for (int i = 1; i <= s.size(); i++) {
    if (m > 0) {
      a[i] = a[i - 1];
      m--;
    } else if (s[i - 1] == 'x') {
      a[i] = a[i - 1];
    } else if (s[i - 1] == 'o') {
      r[i] = true;
      a[i] = a[i - 1] + 1;
      m = c;
    }
  }

  for (int i = 1; i <= n; i++) {
    xx[i] = w;
    if (r[i]) {
      w = i;
      xx[i] = w;
    }
  }

  m = 0;
  for (int i = s.size(); i >= 1; i--) {
    if (m > 0) {
      b[i] = b[i + 1];
      m--;
    } else if (s[i - 1] == 'x') {
      b[i] = b[i + 1];
    } else if (s[i - 1] == 'o') {
      b[i] = b[i + 1] + 1;
      m = c;
    }
  }

  for (int i = 1; i <= n; i++) {
    g[i] = f;
    if (s[i - 1] == 'o')
      f = i;
  }

  f = 0;
  for (int i = n; i >= 1; i--) {
    h[i] = f;
    if (s[i - 1] == 'o')
      f = i;
  }

  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == 'x')
      continue;
    if (g[i] == 0)
      p = 0;
    else
      p = a[g[i]];
    int e = xx[g[i]];
    if (e == 0)
      e = i + 1;
    else
      e = max(e + c + 1, i + 1);
    // cout << e << endl;
    if (e > n)
      q = 0;
    else
      q = b[e];
    // cout << "e = " << e << endl;
    // cout << i << " " << p << " " << q << " ";
    if (i - c - 1 <= 0)
      u = 0;
    else
      u = a[i - c - 1];
    if (i + c + 1 > n)
      v = 0;
    else
      v = a[i + c + 1];
    // cout << u + v << endl;
    if (p + q < k && u + v + 1 >= k)
      cout << i << endl;
  }
}