Submission #1099079

#TimeUsernameProblemLanguageResultExecution timeMemory
1099079Zero_OPSecret (JOI14_secret)C++14
100 / 100
323 ms4680 KiB
#include <bits/stdc++.h> #ifndef LOCAL #include <secret.h> #endif using namespace std; const int MAX = 1e3 + 5; int n, a[MAX], left_suffix[12][MAX], right_prefix[12][MAX]; bool vis[MAX]; #ifdef LOCAL int Secret(int X, int Y){ return min(X + ((Y >> 1) << 1), 1000000000); } #endif void dnc(int l, int r, int layer){ if(l > r) return; int mid = l + r >> 1; if(vis[mid]) return; vis[mid] = true; left_suffix[layer][mid] = a[mid]; for(int i = mid - 1; i >= l; --i){ left_suffix[layer][i] = Secret(a[i], left_suffix[layer][i + 1]); } if(mid < r) { right_prefix[layer][mid + 1] = a[mid + 1]; for(int i = mid + 2; i <= r; ++i){ right_prefix[layer][i] = Secret(right_prefix[layer][i - 1], a[i]); } } dnc(l, mid, layer + 1); dnc(mid + 1, r, layer + 1); } int solve(int lq, int rq, int l, int r, int level){ int mid = l + r >> 1; if(lq <= mid && mid <= rq){ if(mid == rq) return left_suffix[level][lq]; return Secret(left_suffix[level][lq], right_prefix[level][rq]); } if(rq < mid) return solve(lq, rq, l, mid, level + 1); else return solve(lq, rq, mid + 1, r, level + 1); } void Init(int N, int A[]){ n = N; copy(A, A + n, a); dnc(0, n - 1, 0); } int Query(int L, int R){ return solve(L, R, 0, n - 1, 0); } #ifdef LOCAL int main(){ int A[] = {1, 4, 7, 2, 5, 8, 3, 6}; Init(8, A); cout << Query(0, 3) << '\n'; cout << Query(1, 7) << '\n'; cout << Query(5, 5) << '\n'; cout << Query(2, 4) << '\n'; return 0; } #endif

Compilation message (stderr)

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