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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vv(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll(c, d)));
#define rep(c, a, b) for (ll c = a; c < b; c++)
#define re(c, b) for (ll c = 0; c < b; c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
// typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k, c;
  std::cin >> n >> k >> c;
  string s;
  std::cin >> s;
  vll L(n + 1, 0), R(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    L[i] = L[i - 1];
    if (s[n - i] == 'x')
      continue;
    if (i >= c + 1)
      L[i] = max(L[i], (L[i - c - 1] + 1));
    else
      L[i] = max(L[i], (ll)1);
  }

  if (c == 0) {
    if (L[n] == k) {
      for (int i = 0; i < n; i++)
        if (s[i] == 'o')
          std::cout << i + 1 << '\\n';
      return 0;
    } else {
      std::cout << '\\n';
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    R[i] = R[i - 1];
    if (s[i - 1] == 'x')
      continue;
    if (i >= c + 1)
      R[i] = max(R[i], (R[i - c - 1] + 1));
    else
      R[i] = max(R[i], (ll)1);
  }
  multiset<vll> mp;
  for (int i = 0;; i++) {
    ll r = n - i - 1, l = i - c + 1;
    // std::cout << max((ll)0, l) << " " << min(n, max(r, (ll)0)) << '\\n';
    ll cos = L[min(n, max(r, (ll)0))] + R[max((ll)0, l)];
    mp.insert(vll{i - c + 1, -1, cos});
    mp.insert(vll{i + 1, 1, cos});
    if (l == n)
      break;
  }
  vll ans(n);
  vll e;
  auto itr = mp.begin();
  multiset<ll> t;

  for (int i = 0; i < n; i++) {
    while (mp.size() && itr != mp.end() && (*itr)[0] <= i) {
      // std::cout << (*itr)[0] << " " <<(*itr)[1] << " " << (*itr)[2] << '\\n';
      if ((*itr)[1] == -1)
        t.insert((*itr)[2]);
      else {
        auto op = t.find((*itr)[2]);
        t.erase(op);
      }
      itr++;
    }
    ans[i] = (*(--t.end()));
    if (s[i] == 'o' && ans[i] < k && L[n] >= k)
      e.push_back(i + 1);
  }

  for (auto E : e)
    std::cout << E << '\\n';
  if (e.size() == 0)
    std::cout << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vv(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll(c, d)));
#define rep(c, a, b) for (ll c = a; c < b; c++)
#define re(c, b) for (ll c = 0; c < b; c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
// typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k, c;
  std::cin >> n >> k >> c;
  string s;
  std::cin >> s;

  vll L(n + 1, 0), R(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    L[i] = L[i - 1];
    if (s[n - i] == 'x')
      continue;
    if (i >= c + 1)
      L[i] = max(L[i], (L[i - c - 1] + 1));
    else
      L[i] = max(L[i], (ll)1);
  }

  if (c == 0) {
    throw runtime_error("error");
  }

  for (int i = 1; i <= n; i++) {
    R[i] = R[i - 1];
    if (s[i - 1] == 'x')
      continue;
    if (i >= c + 1)
      R[i] = max(R[i], (R[i - c - 1] + 1));
    else
      R[i] = max(R[i], (ll)1);
  }

  multiset<vll> mp;
  for (int i = 0;; i++) {
    ll r = n - i - 1, l = i - c + 1;
    // std::cout << max((ll)0, l) << " " << min(n, max(r, (ll)0)) << '\\n';
    ll cos = L[min(n, max(r, (ll)0))] + R[max((ll)0, l)];
    mp.insert(vll{i - c + 1, -1, cos});
    mp.insert(vll{i + 1, 1, cos});
    if (l == n)
      break;
  }

  vll ans(n);
  vll e;
  auto itr = mp.begin();
  multiset<ll> t;

  for (int i = 0; i < n; i++) {
    while (mp.size() && itr != mp.end() && (*itr)[0] <= i) {
      // std::cout << (*itr)[0] << " " <<(*itr)[1] << " " << (*itr)[2] << '\\n';
      if ((*itr)[1] == -1)
        t.insert((*itr)[2]);
      else {
        auto op = t.find((*itr)[2]);
        t.erase(op);
      }
      itr++;
    }
    ans[i] = (*(--t.end()));
    if (s[i] == 'o' && ans[i] < k && L[n] >= k)
      e.push_back(i + 1);
  }

  for (auto E : e)
    std::cout << E << '\\n';
  if (e.size() == 0)
    std::cout << '\\n';
  return 0;
}