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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x, y) memset(x, y, sizeof(x))
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define per(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define rng(i, a, b) for (int i = int(a); i <= int(b); i++)
#define gnr(i, b, a) for (int i = int(b); i >= int(a); i--)
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,
                         tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template <class T> using vt = vector<T>;
template <class T> using vvt = vt<vt<T>>;
template <class TA, class TB> void chmax(TA &a, TB b) {
  if (a < b)
    a = b;
}
template <class TA, class TB> void chmin(TA &a, TB b) {
  if (b < a)
    a = b;
}
template <class TA, class TB>
ostream &operator<<(ostream &os, const pair<TA, TB> &p) {
  return os << "{" << p.fi << "," << p.se << "}";
}
template <class T> ostream &operator<<(ostream &os, const vt<T> &v) {
  os << "{";
  for (auto &e : v)
    os << e << ",";
  return os << "}";
}
template <class TH> void _dmp(const char *sdbg, TH h) {
  cout << sdbg << "=" << h << endl;
}
template <class TH, class... TA> void _dmp(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',')
    cout << *sdbg++;
  cout << "=" << h << ",";
  _dmp(sdbg + 1, a...);
}
template <class T> void make_unique(vt<T> &v) {
  sort(all(v));
  v.erase(unique(all(v)), v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int ri() {
  int x;
  cin >> x;
  return x;
}
ll rll() {
  ll x;
  cin >> x;
  return x;
}
vi rvi(int n) {
  vi v;
  rep(i, n) v.pb(ri());
  return v;
}
int n, K, C;
int D[200010], E[200010], F[200010];
char s[200010];
void MAIN() {
  cin >> n >> K >> C >> s;
  rep(i, n) {
    if (i >= 1)
      D[i] = max(D[i], D[i - 1]);
    if (i >= C && s[i - C] == 'o')
      D[i] = max(D[i], (i >= C + 1 ? D[i - C - 1] : 0) + 1);
  }
  per(i, n) {
    E[i] = max(E[i], E[i + 1]);
    if (s[i] == 'o')
      E[i] = max(E[i], E[i + C + 1] + 1);
  }
  rep(i, n) {
    if (s[i] == 'o') {
      F[i] = 1;
      if (i >= 1)
        F[i] += D[i - 1];
      if (i + C + 1 < n)
        F[i] += E[i + C + 1];
    }
  }
  vi v;
  deque<int> dq;
  rep(i, n) {
    while (!dq.empty() && dq.front() < i - C)
      dq.pop_front();
    int val = 0;
    if (i)
      val += D[i - 1];
    if (i + 1 < n)
      val += E[i + 1];
    if (!dq.empty())
      val = max(val, F[dq.front()]);
    if (val < K)
      v.pb(i);
    while (!dq.empty() && F[dq.back()] < F[i])
      dq.pop_back();
    dq.push_back(i);
  }
  for (auto &it : v)
    cout << it + 1 << '\\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin>>T;
  for (int tt = 1; tt <= T; tt++) {
    MAIN();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x, y) memset(x, y, sizeof(x))
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define per(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define rng(i, a, b) for (int i = int(a); i <= int(b); i++)
#define gnr(i, b, a) for (int i = int(b); i >= int(a); i--)
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,
                         tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template <class T> using vt = vector<T>;
template <class T> using vvt = vt<vt<T>>;
template <class TA, class TB> void chmax(TA &a, TB b) {
  if (a < b)
    a = b;
}
template <class TA, class TB> void chmin(TA &a, TB b) {
  if (b < a)
    a = b;
}
template <class TA, class TB>
ostream &operator<<(ostream &os, const pair<TA, TB> &p) {
  return os << "{" << p.fi << "," << p.se << "}";
}
template <class T> ostream &operator<<(ostream &os, const vt<T> &v) {
  os << "{";
  for (auto &e : v)
    os << e << ",";
  return os << "}";
}
template <class TH> void _dmp(const char *sdbg, TH h) {
  cout << sdbg << "=" << h << endl;
}
template <class TH, class... TA> void _dmp(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',')
    cout << *sdbg++;
  cout << "=" << h << ",";
  _dmp(sdbg + 1, a...);
}
template <class T> void make_unique(vt<T> &v) {
  sort(all(v));
  v.erase(unique(all(v)), v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int ri() {
  int x;
  cin >> x;
  return x;
}
ll rll() {
  ll x;
  cin >> x;
  return x;
}
vi rvi(int n) {
  vi v;
  rep(i, n) v.pb(ri());
  return v;
}
int n, K, C;
int D[200010], E[200010], F[200010];
char s[200010];
void MAIN() {
  cin >> n >> K >> C >> s;
  rep(i, n) {
    if (i >= 1)
      D[i] = max(D[i], D[i - 1]);
    if (i >= C && s[i - C] == 'o')
      D[i] = max(D[i], D[i - C] + 1);
  }
  per(i, n) {
    E[i] = max(E[i], E[i + 1]);
    if (s[i] == 'o')
      E[i] = max(E[i], E[i + C + 1] + 1);
  }
  rep(i, n) {
    if (s[i] == 'o') {
      F[i] = 1;
      if (i)
        F[i] += D[i - 1];
      if (i + C + 1 < n)
        F[i] += E[i + C + 1];
    }
  }
  vi v;
  deque<int> dq;
  rep(i, n) {
    while (!dq.empty() && dq.front() < i - C)
      dq.pop_front();
    int val = 0;
    if (i)
      val += D[i - 1];
    if (i + 1 < n)
      val += E[i + 1];
    if (i)
      val = max(val, F[dq.front()]);
    if (val < K)
      v.pb(i);
    while (!dq.empty() && F[dq.back()] < F[i])
      dq.pop_back();
    dq.push_back(i);
  }
  for (auto &it : v)
    cout << it + 1 << '\\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin>>T;
  for (int tt = 1; tt <= T; tt++) {
    MAIN();
  }
  return 0;
}