# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
222925 | lyc | Secret (JOI14_secret) | C++14 | 529 ms | 4488 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"
using namespace std;
#define SZ(x) ((int)(x).size())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
struct DST {
static const int MX_N = 1024;
static const int LG_N = 10;
static const int E = 0;
static inline int func(int x, int y) { return Secret(x,y); }
int N, v[LG_N+1][MX_N];
inline void build(int n, int *a) {
for (N = 1; N < n; N <<= 1);
FOR(i,0,n-1) v[0][i] = a[i];
FOR(i,n,N-1) v[0][i] = E;
for (int h = 1, seg = 2; seg <= N; ++h, seg <<= 1) {
for (int i = seg>>1, ss = (seg>>1)-1; i < n; i += seg) {
v[h][i] = a[i];
v[h][i-1] = a[i-1];
FOR(j,1,ss){
v[h][i-1-j] = func(a[i-1-j],v[h][i-j]);
if (i+j < n) v[h][i+j] = func(v[h][i+j-1],a[i+j]); // NOT commutative!
}
}
}
}
int query(int i, int j) {
if (i == j) return v[0][i];
int h = (31-__builtin_clz(i^j)) + 1; // MSB + 1
return func(v[h][i],v[h][j]);
}
} dst;
void Init(int N, int A[]) {
dst.build(N,A);
}
int Query(int L, int R) {
return dst.query(L,R);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |