# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
703797 | TS_2392 | Secret (JOI14_secret) | C++17 | 0 ms | 0 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;
const int N = 1002;
int n, a[N], calc[N][N];
int Secret(int x, int y){
return x + (y / 2) * 2;
}
void dnc(int L, int R){
if(L + 1 >= R) return;
int mid = L + R >> 1;
calc[mid][mid] = a[mid], calc[mid + 1][mid + 1] = a[mid + 1];
for(int i = mid - 1; i >= L; --i) calc[i][mid] = Secret(a[i], calc[i + 1][mid]);
for(int i = mid + 2; i <= R; ++i) calc[mid + 1][i] = Secret(calc[mid + 1][i - 1], a[i]);
dnc(L, mid); dnc(mid + 1, R);
}
void Init(int N_, int A[]){
n = N_;
for(int i = 1; i <= n; ++i) a[i] = A[i - 1];
memset(calc, 255, sizeof(calc)); dnc(1, n);
}
int Query(int L, int R){
++L; ++R;
if(L == R) return a[L];
if(L + 1 == R) return Secret(a[L], a[R]);
int i;
for(i = L; i < R; ++i) if(calc[L][i] != -1 && calc[i + 1][R] != -1) break;
return Secret(calc[L][i], calc[i + 1][R]);
}