# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1069471 | Boycl07 | Secret (JOI14_secret) | C++17 | 338 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;
#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "FFILL"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
const int Max_N = 1e3 + 1;
const int LOG = 9;
int n, a[Max_N];
int st[Max_N][LOG + 1], pos[Max_N];
void dnc(int l, int r, int stage)
{
if(l == r) return;
int mid = l + r >> 1;
st[mid][stage] = a[mid];
st[mid + 1][stage] = a[mid + 1]; pos[mid + 1] |= (1 << stage);
ford(i, mid - 1, l) st[i][stage] = Secret(a[i], st[i + 1][stage]);
forn(i, mid + 2, r) st[i][stage] = Secret(st[i - 1][stage], a[i]), pos[i] |= (1 << stage);
dnc(l, mid, stage + 1);
dnc(mid + 1, r, stage + 1);
}
void Init(int N, int A[])
{
n = N;
FOR(i, n) a[i] = A[i];
dnc(0, n - 1, 0);
}
int Query(int l, int r)
{
if(l == r) return a[l];
int stage = __builtin_ctz(pos[l] ^ pos[r]);
return Secret(st[l][stage], st[r][stage]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |