/ SeriousOJ /

Record Detail

Compile Error

foo.cc: In function 'int main()':
foo.cc:43:5: error: return-statement with no value, in function returning 'int' [-fpermissive]
   43 |     return;
      |     ^~~~~~

Code

#include <bits/stdc++.h>
using namespace std;

const int N = (int)2e5 + 9;
int lg[N];
void Preprocess() {
  for (int i = 2; i < N; ++i) {
    lg[i] = lg[i / 2] + 1;
  }
}
template <class T> struct RMQ {
  int n = 1, LOG = 1;
  vector<vector<T>> st;
  T Merge(T& a, T& b) {
    return min(a, b);
  }
  RMQ() {}
  RMQ(vector<T>& a) {
    if (lg[2] == 0) Preprocess();
    n = (int)a.size(), LOG = __lg(n) + 1;
    st.assign(n, vector<T> (LOG));
    for (int j = 0; j < LOG; j++) {
      for (int i = 0; i + (1 << j) - 1 < n; i++) {
        if (j == 0) st[i][j] = a[i];
        else st[i][j] = Merge(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
      }
    }
  }
  T Query(int l, int r) {
    int k = lg[r - l + 1];
    return Merge(st[l][k], st[r - (1 << k) + 1][k]);
  }
};

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, k;
  cin >> n >> k;
  string a;
  cin >> a;
  if (k == 1) {
    cout << a << '\n';
    return;
  }
  a = "#" + a;
  vector<int> b(n + 1);
  for (int i = 1; i <= n; i++) {
    b[i] = a[i] - 'a';
  }
  RMQ rmq(b);
  for (int i = 1, j = k; j <= n; i++, j++) {
    if (b[i] > rmq.Query(i + 1, j)) {
      sort(a.begin() + i, a.begin() + j + 1);
      i += k - 1;
      j += k - 1;
    }
  }
  a.erase(0, 1);
  cout << a << '\n';
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1230 Lexicographically Smallest Rearrangement
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 17:10:25
Judged At
2025-09-02 17:10:25
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes