# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
222915 | lyc | 비밀 (JOI14_secret) | C++14 | 546 ms | 4520 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]);
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... |