Submission #784414

#TimeUsernameProblemLanguageResultExecution timeMemory
784414chanhchuong123Secret (JOI14_secret)C++14
0 / 100
404 ms8592 KiB
#include "secret.h" #include <bits/stdc++.h> using namespace std; const int MAX = 1024; int n; int a[MAX]; int mask[MAX]; int dp[15][MAX]; void divi(int l, int r, int lev) { if (l == r) return; int mid = l + r >> 1; dp[lev][mid] = a[mid]; dp[lev][mid + 1] = a[mid + 1]; for (int i = mid - 1; i >= l; --i) dp[lev][i] = Secret(dp[lev][i + 1], a[i]); for (int i = mid + 2; i <= r; ++i) dp[lev][i] = Secret(dp[lev][i - 1], a[i]); for (int i = mid + 1; i <= r; ++i) mask[i] = 1 << lev; divi(l, mid, lev + 1); divi(mid + 1, r, lev + 1); } void Init(int N, int A[]) { n = N; for (int i = 0; i < n; ++i) { a[i] = A[i]; mask[i] = 0; } divi(0, n - 1, 0); } int Query(int L, int R) { if (L == R) return a[L]; int lev = __builtin_ctz(mask[L] ^ mask[R]); return Secret(dp[lev][L], dp[lev][R]); }

Compilation message (stderr)

secret.cpp: In function 'void divi(int, int, int)':
secret.cpp:13:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |     int mid = l + r >> 1;
      |               ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...