Submission #502844

#TimeUsernameProblemLanguageResultExecution timeMemory
502844gozoniteSecret (JOI14_secret)C++14
100 / 100
512 ms4412 KiB
#include <iostream> #include <vector> #include <string> #include <fstream> #include <algorithm> #include <climits> #include <cstdlib> #include <cstdio> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <bitset> #include <deque> #include <queue> #include <tuple> #include <cmath> #include <cctype> #include <stack> #include <cassert> #include "secret.h" using namespace std; using ll = long long; int dat[11][1000]; int mask[1000]; int a[1000]; void build(int l, int r, int A[], int lev) { if (l == r) return; int mid = (l+r)/2; dat[lev][mid] = A[mid]; dat[lev][mid+1] = A[mid+1]; for (int i = mid-1; i >= l; i--) dat[lev][i] = Secret(A[i], dat[lev][i+1]); for (int i = mid+2; i <= r; i++) dat[lev][i] = Secret(dat[lev][i-1], A[i]); for (int i = mid+1; i <= r; i++) mask[i] ^= 1<<lev; build(l, mid, A, lev+1); build(mid+1, r, A, lev+1); } void Init(int N, int A[]) { build(0, N-1, A, 0); for (int i = 0; i < N; i++) a[i] = A[i]; } int Query(int L, int R) { if (L == R) return a[L]; int lev = __builtin_ctz(mask[L]^mask[R]); return Secret(dat[lev][L], dat[lev][R]); }
#Verdict Execution timeMemoryGrader output
Fetching results...