# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
354231 | parsabahrami | Secret (JOI14_secret) | C++17 | 522 ms | 4588 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;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int N = 1e3 + 10;
int M[N], B[11][N], A[N], n;
void divide(int l = 0, int r = n, int h = 0) {
if (r - l < 2) {
B[h][l] = A[l];
return;
}
int mid = (l + r) >> 1;
B[h][mid] = A[mid], B[h][mid - 1] = A[mid - 1];
for (int i = mid - 2; i >= l; i--) B[h][i] = Secret(A[i], B[h][i + 1]);
for (int i = mid + 1; i < r; i++) B[h][i] = Secret(B[h][i - 1], A[i]);
for (int i = mid; i < r; i++) M[i] |= 1 << h;
divide(l, mid, h + 1), divide(mid, r, h + 1);
}
void Init(int _n, int a[]) {
n = _n;
for (int i = 0; i < n; i++) A[i] = a[i];
divide();
}
int Query(int L, int R) {
if (L == R) return A[L];
else {
int c = __builtin_ctz(M[L] ^ M[R]);
return Secret(B[c][L], B[c][R]);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |