# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1043769 | Tofu | Secret (JOI14_secret) | C++11 | 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 "secret.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define pii pair<int, int>
#define pll pair<ll, ll>
const int MAXN = 1005;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const ll BFN = (ll)1e16;
// const int BFN = (int)1e8;
int n;
int a[MAXN];
int ans[20][MAXN];
void F(int lv, int l, int r) {
if(l == r) {
ans[lv][l] = a[l];
return;
}
int m = (l + r) / 2;
ans[lv][m] = a[m];
for(int i = m-1; i >= l; i--) {
ans[lv][i] = Secret(a[i], ans[lv][i+1]);
}
ans[lv][m+1] = a[m+1];
for(int i = m+2; i <= r; i++) {
ans[lv][i] = Secret(ans[lv][i-1], a[i]);
}
F(lv+1, l, m);
F(lv+1, m+1, r);
}
int G(int lv, int l, int r, int ql, int qr) {
int m = (l+r)/2;
if(qr <= m) {
return G(lv+1, l, m, ql, qr);
}
if(m+1 <= ql) {
return G(lv+1, m+1, r, ql, qr);
}
return Secret(ans[lv][ql], ans[lv][qr]);
}
void Init(int N, int A[]) {
n = N;
for(int i = 1; i <= n; i++) a[i] = A[i-1];
F(1, 1, n);
}
int Query(int L, int R) {
if(L == R) return a[L];
return G(1, 1, n, L, R);
}