Submission #605830

#TimeUsernameProblemLanguageResultExecution timeMemory
605830socpiteSecret (JOI14_secret)C++14
0 / 100
20091 ms8388 KiB
#include "secret.h" #include<bits/stdc++.h> using namespace std; #define f first #define s second typedef long long ll; const int maxn = 1005; int pfx[4*maxn][maxn], sfx[4*maxn][maxn]; int arr[maxn]; int n; void build(int l, int r, int id){ if(r-l<=1)return; int mid = (l+r)>>1; pfx[id][0]=arr[mid+1]; sfx[id][0]=arr[mid]; for(int i = mid+2; i <= r; i++){ pfx[id][i-mid-1]=Secret(pfx[id][i-mid-2], arr[i]); } for(int i = 1; i < mid+1-l; i++){ sfx[id][i]=Secret(arr[mid-i], sfx[id][i-1]); } build(l, mid, id<<1); build(mid+1, r, id<<1|1); } int gt(int l, int r, int ql, int qr, int id){ int mid = (l+r)>>1; if(qr < mid)return gt(l, r, ql, qr, id<<1); else if(ql > mid+1)return gt(mid+1, r, ql, qr, id<<1|1); else{ int re = -1; if(ql <= mid)re = sfx[id][mid-ql]; if(qr >= mid+1){ if(re < 0)re = pfx[id][qr-mid-1]; else re = Secret(re, pfx[id][qr-mid-1]); } return re; } } int Query(int L, int R){ if(L==R)return arr[L]; else if(R-1==L)return Secret(arr[L], arr[R]); else return gt(0, n-1, L, R, 1); } void Init(int N, int A[]){ n = N; for(int i = 0; i < n; i++)arr[i]=A[i]; build(0, n-1, 1); }
#Verdict Execution timeMemoryGrader output
Fetching results...