Submission #570969

#TimeUsernameProblemLanguageResultExecution timeMemory
570969four_specksSecret (JOI14_secret)C++17
100 / 100
456 ms4492 KiB
#include "secret.h" #include <bits/stdc++.h> using namespace std; inline namespace ns { template <typename T, typename Op> struct SRQ { explicit SRQ(const vector<T> &vec, Op _op = Op()) : n((int)vec.size()), table(__lg(n) + 1, vector<T>(n)), op(_op) { table[0] = vec; for (int x = 1; x < (int)table.size(); x++) { int j = 1 << x; for (int i = j; i < n; i += j << 1) { table[x][i - 1] = vec[i - 1]; for (int l = i - 2, r = i - j; l >= r; l--) table[x][l] = op(vec[l], table[x][l + 1]); table[x][i] = vec[i]; for (int l = i + 1, r = min(n, i + j); l < r; l++) table[x][l] = op(table[x][l - 1], vec[l]); } } } T query(int l, int r) const { assert(l < r); --r; if (l == r) return table[0][l]; int x = __lg(l ^ r); return op(table[x][l], table[x][r]); } private: int n; vector<vector<T>> table; Op op; }; } // namespace ns namespace { SRQ<int, decltype(&Secret)> *srq; } void Init(int N, int A[]) { static SRQ _srq(vector(A, A + N), Secret); srq = &_srq; } int Query(int L, int R) { return srq->query(L, R + 1); }
#Verdict Execution timeMemoryGrader output
Fetching results...