# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
656563 | Tuanlinh123 | Secret (JOI14_secret) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
map <pair<int, int>, int> Map;
int a[1005], NN;
void prep(int l, int r)
{
if (r-l<=1)
return;
int mid=(l+r)/2;
int crr=a[mid-1];
for (int i=mid-2; i>=l; i--)
{
crr=Secret(a[i], crr);
Map[{i, mid-1}]=crr;
}
crr=a[mid];
for (int i=mid+1; i<=r; i++)
{
crr=Secret(crr, a[i]);
Map[{mid, i}]=crr;
}
prep(l, mid-1);
prep(mid+1, r);
}
void Init(int n, int A[])
{
NN=n;
for (int i=0; i<n; i++)
{
a[i]=A[i];
Map[{i, i}]=a[i];
}
prep(0, n-1);
}
int Find(int L, int R, int tl, int tr)
{
int mid=(L+R)/2;
if (mid>=tl && mid<=tr)
return mid;
if (mid<tl)
return Find(mid+1, R, tl, tr);
return Find(L, mid-1, tl, tr);
}
int Query(int L, int R)
{
if (L==R)
return a[L];
if (L+1==R)
return Secret(a[L], a[R]);
int mid=Find(0, NN-1, L, R);
if (mid==L)
return Map[{mid, R}];
return Secret(Map[{L, mid-1}], Map[{mid, R}]);
}