Language: C++



    SegTree<pair<int, int>>::fn merge = [] (pair<int, int> a, pair<int, int> b) {
      if (a.first != b.first) return a < b ? a : b;
      return a.second < b.second ? b : a;
    };
    const int inf = 1 << 29;
    SegTree<pair<int, int>> segtree(merge, make_pair(inf, -1), s.size());
    segtree.update(0, make_pair(0, 0));

    reverse(s.begin(), s.end());
    const int N = 1e5 + 5;
    static int prev[N];
    fill(prev, prev + N, -1);
    prev[0] = 0;
    for (int i = 1; i < s.size(); ++i) {
      if (s[i] == '1') continue;
      auto mn = segtree.query(max(0, i - m), i);
      auto p = make_pair(mn.first + 1, i);
      segtree.update(i, p);
      prev[i] = mn.second;
    }

    if (inf <= segtree.query(s.size() - 1, s.size()).first) {
      cout << -1 << endl;
      continue;
    }

    vector<int> path;
    for (int curr = s.size() - 1; curr; curr = prev[curr]) {
      path.push_back(curr);
    }
    path.push_back(0);
    vector<int> v;
    for (int i = 0; i + 1 < path.size(); ++i) {
      v.push_back(path[i] - path[i + 1]);
    }
    each (i, v) cout << i << ' '; cout << endl;
  }

  return 0;


Compiler output:
a.cc:3:5: error: 'SegTree' does not name a type
    3 |     SegTree<pair<int, int>>::fn merge = [] (pair<int, int> a, pair<int, int> b) {
      |     ^~~~~~~
a.cc:8:5: error: 'SegTree' does not name a type
    8 |     SegTree<pair<int, int>> segtree(merge, make_pair(inf, -1), s.size());
      |     ^~~~~~~
a.cc:9:5: error: 'segtree' does not name a type
    9 |     segtree.update(0, make_pair(0, 0));
      |     ^~~~~~~
a.cc:11:12: error: expected constructor, destructor, or type conversion before '(' token
   11 |     reverse(s.begin(), s.end());
      |            ^
a.cc:14:9: error: expected constructor, destructor, or type conversion before '(' token
   14 |     fill(prev, prev + N, -1);
      |         ^
a.cc:15:5: error: 'prev' does not name a type
   15 |     prev[0] = 0;
      |     ^~~~
a.cc:16:5: error: expected unqualified-id before 'for'
   16 |     for (int i = 1; i < s.size(); ++i) {
      |     ^~~
a.cc:16:21: error: 'i' does not name a type
   16 |     for (int i = 1; i < s.size(); ++i) {
      |                     ^
a.cc:16:35: error: expected unqualified-id before '++' token
   16 |     for (int i = 1; i < s.size(); ++i) {
      |                                   ^~
a.cc:24:5: error: expected unqualified-id before 'if'
   24 |     if (inf <= segtree.query(s.size() - 1, s.size()).first) {
      |     ^~
a.cc:29:5: error: 'vector' does not name a type
   29 |     vector<int> path;
      |     ^~~~~~
a.cc:30:5: error: expected unqualified-id before 'for'
   30 |     for (int curr = s.size() - 1; curr; curr = prev[curr]) {
      |     ^~~
a.cc:30:35: error: 'curr' does not name a type
   30 |     for (int curr = s.size() - 1; curr; curr = prev[curr]) {
      |                                   ^~~~
a.cc:30:41: error: 'curr' does not name a type
   30 |     for (int curr = s.size() - 1; curr; curr = prev[curr]) {
      |                                         ^~~~
a.cc:33:5: error: 'path' does not name a type
   33 |     path.push_back(0);
      |     ^~~~
a.cc:34:5: error: 'vector' does not name a type
   34 |     vector<int> v;
      |     ^~~~~~
a.cc:35:5: error: expected unqualified-id before 'for'
   35 |     for (int i = 0; i + 1 < path.size(); ++i) {
      |     ^~~
a.cc:35:21: error: 'i' does not name a type
   35 |     for (int i = 0; i + 1 < path.size(); ++i) {
      |                     ^
a.cc:35:42: error: expected unqualified-id before '++' token
   35 |     for (int i = 0; i + 1 < path.size(); ++i) {
      |                                          ^~
a.cc:38:10: error: expected constructor, destructor, or type conversion before '(' token
   38 |     each (i, v) cout << i << ' '; cout << endl;
      |          ^
a.cc:38:35: error: 'cout' does not name a type
   38 |     each (i, v) cout << i << ' '; cout << endl;
      |                                   ^~~~
a.cc:39:3: error: expected declaration before '}' token
   39 |   }
      |   ^
a.cc:41:3: error: expected unqualified-id before 'return'
   41 |   return 0;
      |   ^~~~~~