# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
52452 | 2018-06-26T04:08:48 Z | tataky(#1353) | Secret (JOI14_secret) | C++11 | 0 ms | 0 KB |
#include "secret.h" int sp[9][1001], to[9][1001], n; int a[1001]; int Query(int L, int R) { if (L == R) return a[L]; int dist = R - L; if (dist < 512) { int ret, cur = L; bool fst = false; for (int h = 8; h >= 0; h--) if(dist&(1<<h)) { if (fst) { ret = sp[h][cur]; cur = to[h][cur]; } else { ret = Secret(ret, sp[h][cur]); cur = to[h][cur]; } } } return ret; } void setsparse() { for (int i = 0; i < n - 1; i++) { sp[i][0] = Secret(a[i], a[i + 1]); to[i][0] = i + 1; } for (int h = 1; h < 9; h++) { for (int i = 0; i < n; i++) if (i + (1 << h) < n) { to[h][i] = to[h - 1][to[h - 1][i]]; sp[h][i] = Secret(sp[h - 1][i], sp[h - 1][to[h - 1][i]]; } } } void Init(int N, int A[]) { n = N; for (int i = 0; i < n; i++) a[i] = A[i]; setsparse(); }