Submission #957090

#TimeUsernameProblemLanguageResultExecution timeMemory
957090MuntherCarrotSecret (JOI14_secret)C++14
100 / 100
415 ms8528 KiB
#include <bits/stdc++.h> #include "secret.h" using namespace std; // int Secret(int X, int Y); const int MAXN = 1010; int block[MAXN][MAXN]; int n; void div(int l, int r, int A[]){ if(l >= r){ block[l][l] = A[l]; return; } int mid = (l + r) / 2; block[mid][mid] = A[mid]; block[mid + 1][mid + 1] = A[mid + 1]; for(int i = mid - 1; i >= l; i--){ block[mid][i] = Secret(A[i], block[mid][i + 1]); } for(int i = mid + 2; i <= r; i++){ block[mid + 1][i] = Secret(block[mid + 1][i - 1], A[i]); } div(l, mid, A); div(mid + 1, r, A); } void Init(int N, int A[]){ n = N; div(0, N - 1, A); } int Query(int L, int R){ int l = 0, r = n - 1; while(l < r){ int mid = (l + r) / 2; if(L <= mid && mid < R){ return Secret(block[mid][L], block[mid + 1][R]); } else if(mid == R){ return block[mid][L]; } else if(mid < L){ l = mid + 1; } else{ r = mid; } } return block[l][l]; } // by me
#Verdict Execution timeMemoryGrader output
Fetching results...