Submission #674792

#TimeUsernameProblemLanguageResultExecution timeMemory
674792Valera_GrinenkoSecret (JOI14_secret)C++17
0 / 100
431 ms4316 KiB
#include "secret.h" #include <vector> using namespace std; template<class T> struct onlineDQ { static const int SZ = (1 << 10); int n; T stor[SZ][32-__builtin_clz(SZ)], id = 1; vector<T> a; T comb (T a, T b) { return Secret(a, b); } // associative operation void fill(int l, int r, int ind) { if(ind == 0) { stor[l][ind] = a[l]; return; } int m = (l+r)/2; stor[m][ind] = a[m]; for(int i = m - 1; i >= l; i--) stor[i][ind] = comb(a[i], stor[i + 1][ind]); stor[m + 1][ind] = a[m + 1]; for(int i = m + 2; i < r; i++) stor[i][ind] = comb(stor[i - 1][ind] ,a[i]); fill(l,m,ind-1); fill(m,r,ind-1); } void init() { n = 1; while ((1<<n) < (int)a.size()) ++n; a.resize(1<<n); fill(0,(1<<n),n-1); } T query(int l, int r) { if (l == r) return a[l]; int t = 31-__builtin_clz(r^l); return comb(stor[l][t],stor[r][t]); } }; onlineDQ<int> odq; void Init(int N, int A[]) { odq.a.resize(N); for(int i = 0; i < N; i++) odq.a[i] = A[i]; odq.init(); } int Query(int L, int R) { return odq.query(L, R); }
#Verdict Execution timeMemoryGrader output
Fetching results...