# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
227133 | arnold518 | Secret (JOI14_secret) | C++14 | 544 ms | 4604 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 ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1000;
int N, A[MAXN+10];
int tree[MAXN+10][30];
void init(int node, int tl, int tr, int dep)
{
int i, j;
if(tl==tr) return;
int mid=tl+tr>>1;
tree[mid][dep]=A[mid];
for(i=mid-1; i>=tl; i--) tree[i][dep]=Secret(A[i], tree[i+1][dep]);
tree[mid+1][dep]=A[mid+1];
for(i=mid+2; i<=tr; i++) tree[i][dep]=Secret(tree[i-1][dep], A[i]);
init(node*2, tl, mid, dep+1);
init(node*2+1, mid+1, tr, dep+1);
}
int query(int node, int tl, int tr, int l, int r, int dep)
{
int mid=tl+tr>>1;
if(l<=mid && mid+1<=r) return Secret(tree[l][dep], tree[r][dep]);
if(r<=mid) return query(node*2, tl, mid, l, r, dep+1);
if(mid+1<=l) return query(node*2+1, mid+1, tr, l, r, dep+1);
}
void Init(int _N, int _A[])
{
int i, j;
N=_N;
for(i=1; i<=N; i++) A[i]=_A[i-1];
init(1, 1, N, 1);
}
int Query(int L, int R)
{
L++; R++;
if(L==R) return A[L];
return query(1, 1, N, L, R, 1);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |