# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
906330 | noobcodur | Secret (JOI14_secret) | C++14 | 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 "secret.h"
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// template <class T>
// using oset =
// tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define _GLIBCXX_DEBUG 1
// #define _GLIBCXX_DEBUG_PEDANTIC 1
// #pragma GCC optimize("trapv")
// #define dbg(TXTMSG) cerr << "\n" << TXTMSG
// #define dbgv(VARN) cerr << "\n" << #VARN << " = "<< VARN << ", line: " << __LINE__ << "\n"
#define int long long
#define forn(i,j) for(int i = 0; i < j; i++)
#define forrange(i,j,k) for(int i = j; i < k; ++i)
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vi>
#define vvpii vector<vector<pii>>
#define vb vector<bool>
#define pb push_back
#define f first
#define s second
const int MOD = 1e9 + 7;
const int INF = 1e17 + 1;
const int maxN = 1e3 + 1;
const int LOG = 11;
int n;
int dnc[LOG][maxN];
void initialize(int lvl, int l, int r, int A[]){
if(l == r){
dnc[lvl][l] = A[l];
return;
}
int mid = (l+r)/2;
dnc[lvl][mid] = A[mid];
dnc[lvl][mid+1] = A[mid+1];
forrange(i,mid+2,n){
dnc[lvl][i] = Secret(dnc[lvl][i-1],A[i]);
}
for(int i = mid-1; i >= 0; --i){
dnc[lvl][i] = Secret(dnc[lvl][i+1],A[i]);
}
initialize(lvl+1,l,mid,A); initialize(lvl+1,mid+1,r,A);
}
int online_query(int lvl, int l, int r, int ql, int qr){
if(l == r){
return dnc[lvl][l];
}
int mid = (l+r)/2;
if(qr <= mid){
return online_query(lvl+1,l,mid,ql,qr);
}
if(ql >= mid+1){
return online_query(lvl+1,mid+1,r,ql,qr);
}
return Secret(dnc[lvl][ql],dnc[lvl][qr]);
}
void Init(int N, int A[]) {
n = N;
initialize(0,0,n-1,A);
}
int Query(int L, int R) {
return online_query(0,0,n-1,L,R);
}