# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
484046 | danielliu04 | Secret (JOI14_secret) | C++17 | 452 ms | 4440 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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(arr[i], dat[level][i+1]);
}
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |