Submission #967832

#TimeUsernameProblemLanguageResultExecution timeMemory
967832NK_Floppy (RMI20_floppy)C++17
100 / 100
75 ms20868 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> #include "floppy.h" using namespace std; #define nl '\n' #define pb push_back #define sz(x) int(x.size()) template<class T> using V = vector<T>; using vi = V<int>; using str = string; V<vi> build(const vi& A) { auto cmb = [&](int a, int b) { return (A[a] > A[b] ? a : b); }; int N = sz(A); V<vi> jmp = {vi(N)}; iota(begin(jmp[0]), end(jmp[0]), 0); for(int i = 1; (1 << i) <= N; i++) { jmp.pb(vi(N - (1 << i) + 1)); for(int x = 0; x < sz(jmp[i]); x++) { jmp[i][x] = cmb(jmp[i - 1][x], jmp[i - 1][x + (1 << (i - 1))]); } } return jmp; } void read_array(int id, const vi &A) { // cout << "HERE" << endl; auto cmb = [&](int a, int b) { return (A[a] > A[b] ? a : b); }; V<vi> st = build(A); auto qry = [&](int l, int r) { if (l == r) return l; int d = 31 - __builtin_clz(r - l + 1); return cmb(st[d][l], st[d][r - (1 << d) + 1]); }; str S; function<void(int, int)> dnc = [&](int l, int r) { if (l > r) return; int m = qry(l, r); // cout << l << " " << m << " " << r << endl; S += char('0' + (l != m)); S += char('0' + (r != m)); dnc(l, m - 1); dnc(m + 1, r); }; dnc(0, sz(A) - 1); save_to_floppy(S); } vi solve_queries(int id, int N, const str &S, const vi &L, const vi &R) { vi ans; vi A; int cur = 0; function<void(int, int)> dfs = [&](int u, int d) { // cout << u << " => " << S[2 * u] << " " << S[2 * u + 1] << endl; if (S[2 * u] == '1') dfs(++cur, d - 1); A.pb(d); if (S[2 * u + 1] == '1') dfs(++cur, d - 1); }; dfs(0, N); // for(auto& x : A) cout << x << " "; // cout << endl; auto cmb = [&](int a, int b) { return (A[a] > A[b] ? a : b); }; V<vi> st = build(A); auto qry = [&](int l, int r) { if (l == r) return l; int d = 31 - __builtin_clz(r - l + 1); return cmb(st[d][l], st[d][r - (1 << d) + 1]); }; for(int i = 0; i < sz(L); i++) ans.pb(qry(L[i], R[i])); return ans; } // g++-13 -std=c++17 -O2 grader.cpp A.cpp -o ./G

Compilation message (stderr)

stub.cpp: In function 'void run2()':
stub.cpp:101:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  101 |     if (query_answers.size() != M) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...