Submission #1013347

#TimeUsernameProblemLanguageResultExecution timeMemory
1013347AverageAmogusEnjoyerSecret (JOI14_secret)C++17
100 / 100
318 ms4436 KiB
#include <bits/stdc++.h> #include "secret.h" using namespace std; using ll = long long; template<class T> bool cmin(T &i, T j) { return i > j ? i=j,true:false; } template<class T> bool cmax(T &i, T j) { return i < j ? i=j,true:false; } mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); int rng() { return abs((int)mrand()); } // Current challenge: finish CSES problemset!! constexpr int nax = 1000, lg = 10; int res[lg][nax]; int mask[nax]; int a[nax]; void build(int l,int r,int pw) { if (l == r) { return; } int m = (l+r)/2; res[pw][m] = a[m]; for (int i=m-1;i>=l;i--) { res[pw][i] = Secret(a[i],res[pw][i+1]); } res[pw][m+1] = a[m+1]; for (int i=m+2;i<=r;i++) { res[pw][i] = Secret(res[pw][i-1],a[i]); } for (int i=m+1;i<=r;i++) { mask[i] ^= 1 << pw; } build(l,m,pw+1); build(m+1,r,pw+1); } void Init(int n,int _a[]) { for (int i=0;i<n;i++) { a[i] = _a[i]; } build(0,n-1,0); } int Query(int l,int r) { if (l == r) { return a[l]; } int bits = __builtin_ctz(mask[l] ^ mask[r]); return Secret(res[bits][l],res[bits][r]); }
#Verdict Execution timeMemoryGrader output
Fetching results...