Submission #354231

#TimeUsernameProblemLanguageResultExecution timeMemory
354231parsabahramiSecret (JOI14_secret)C++17
100 / 100
522 ms4588 KiB
#include "secret.h" #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second const int N = 1e3 + 10; int M[N], B[11][N], A[N], n; void divide(int l = 0, int r = n, int h = 0) { if (r - l < 2) { B[h][l] = A[l]; return; } int mid = (l + r) >> 1; B[h][mid] = A[mid], B[h][mid - 1] = A[mid - 1]; for (int i = mid - 2; i >= l; i--) B[h][i] = Secret(A[i], B[h][i + 1]); for (int i = mid + 1; i < r; i++) B[h][i] = Secret(B[h][i - 1], A[i]); for (int i = mid; i < r; i++) M[i] |= 1 << h; divide(l, mid, h + 1), divide(mid, r, h + 1); } void Init(int _n, int a[]) { n = _n; for (int i = 0; i < n; i++) A[i] = a[i]; divide(); } int Query(int L, int R) { if (L == R) return A[L]; else { int c = __builtin_ctz(M[L] ^ M[R]); return Secret(B[c][L], B[c][R]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...