제출 #508653

#제출 시각아이디문제언어결과실행 시간메모리
508653Abrar_Al_Samit비밀 (JOI14_secret)C++17
0 / 100
483 ms4316 KiB
#include "secret.h" #include <bits/stdc++.h> const int MX = 1001; int tab[10][MX]; int mask[MX]; int n, a[MX]; void prepare(int l, int r, int level) { if(l==r) return; int m = (l+r)/2; tab[level][m] = a[m]; tab[level][m+1] = a[m+1]; for(int i=m-1; i>=l; --i) { tab[level][i] = Secret(a[i], tab[level][i+1]); } for(int i=m+2; i<=r; ++i) { tab[level][i] = Secret(a[i], tab[level][i-1]); } for(int i=m+1; i<=r; ++i) { mask[i] ^= 1<<level; } prepare(l, m, level+1); prepare(m+1, r, level+1); } void Init(int N, int A[]) { n = N; for(int i=0; i<n; ++i) { a[i] = A[i]; } prepare(0, n-1, 0); } int Query(int L, int R) { if(L==R) return a[L]; int level = __builtin_ctz(mask[L]^mask[R]); return Secret(tab[level][L], tab[level][R]); }
#Verdict Execution timeMemoryGrader output
Fetching results...