Submission #41568

#TimeUsernameProblemLanguageResultExecution timeMemory
41568funcsrSecret (JOI14_secret)C++14
100 / 100
624 ms12536 KiB
#include "secret.h" #include <iostream> #include <vector> #include <algorithm> using namespace std; #define rep(i, n) for (int i=0; i<(n); i++) #define all(x) x.begin(), x.end() #define uniq(x) x.erase(unique(all(x)), x.end()) #define index(x, y) (int)(lower_bound(all(x), y) - x.begin()) #define pb push_back #define MAX_N (1<<10) int N; int A[1000]; int Tleft[1000][1000], Tright[1000][1000]; void precalc(int l, int r) { if (l == r) return; int mid = (l+r)/2; Tleft[mid][mid] = A[mid]; for (int x=mid-1; x>=l; x--) Tleft[mid][x] = Secret(A[x], Tleft[mid][x+1]); Tright[mid][mid+1] = A[mid+1]; for (int x=mid+2; x<=r; x++) Tright[mid][x] = Secret(Tright[mid][x-1], A[x]); precalc(l, mid); precalc(mid+1, r); } int f(int l, int r, int a, int b) { if (l == r) return A[l]; int mid = (l+r)/2; if (a <= mid && mid <= b) { int x = Tleft[mid][a]; if (mid < b) x = Secret(x, Tright[mid][b]); return x; } if (b < mid) return f(l, mid, a, b); else return f(mid+1, r, a, b); } void Init(int NN, int AA[]) { N = NN; rep(i, N) A[i] = AA[i]; precalc(0, N-1); } int Query(int L, int R) { return f(0, N-1, L, R); }
#Verdict Execution timeMemoryGrader output
Fetching results...