Submission #484042

#TimeUsernameProblemLanguageResultExecution timeMemory
484042danielliu04Secret (JOI14_secret)C++17
0 / 100
428 ms4392 KiB
// Link: https://cses.fi/problemset/task/1647 #include <bits/stdc++.h> #include "secret.h" using namespace std; #define ll long long #define lc (node<<1)+1 #define rc (node<<1)+2 #define endl '\n' #define INF 1e9 const int max_n = 1000; const int max_log = (int)log2(max_n) + 2; int dat[max_log][max_n]; int arr[max_n], mask[max_n]; void divi(int left, int right, int level){ if(left == right) return; int mid = (left + right) / 2; dat[level][mid] = arr[mid]; for(int i = mid-1; i >= left; i --){ dat[level][i] = Secret(dat[level][i+1], arr[i]); } dat[level][mid+1] = arr[mid+1]; for(int i = mid+2; i <= right; i ++){ dat[level][i] = Secret(dat[level][i-1], arr[i]); } for(int i = mid+1; i <= right; i ++){ mask[i] |= (1 << level); } divi(left, mid, level+1); divi(mid+1, right, level + 1); } void Init(int N, int A[]){ for(int i = 0; i < N; i ++){ arr[i] = A[i]; } divi(0, N-1, 0); } int Query(int L, int R){ if(L == R) return arr[L]; int bits = __builtin_ctz(mask[L] ^ mask[R]); return Secret(dat[bits][L], dat[bits][R]); }
#Verdict Execution timeMemoryGrader output
Fetching results...