Submission #380502

#TimeUsernameProblemLanguageResultExecution timeMemory
380502pure_memSecret (JOI14_secret)C++14
100 / 100
536 ms9492 KiB
#include "secret.h" #include <bits/stdc++.h> #define X first #define Y second #define MP make_pair #define ll long long using namespace std; int q[1001][1001]; bool was[1001][1001]; void Init(int N, int A[]) { stack< pair<int, int> > st; st.push(MP(1, N)); while(!st.empty()){ int l = st.top().X, r = st.top().Y; st.pop(); int m = (l + r) / 2; was[m][m] = 1, q[m][m] = A[m - 1]; for(int i = m - 1, j = A[m - 1];i >= l;i--){ j = Secret(A[i - 1], j), q[i][m] = j, was[i][m] = 1; } if(l == r) continue; was[m + 1][m + 1] = 1, q[m + 1][m + 1] = A[m]; for(int i = m + 2, j = A[m];i <= r;i++){ j = Secret(j, A[i - 1]), q[m + 1][i] = j, was[m + 1][i] = 1; } if(l != r) st.push(MP(l, m)), st.push(MP(m + 1, r)); } // Secret(0, 1000000000); } int Query(int L, int R) { L += 1, R += 1; if(was[L][R]) return q[L][R]; for(int i = L;i < R;i++){ if(was[L][i] && was[i + 1][R]) return Secret(q[L][i], q[i + 1][R]); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...