# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
165325 | jovan_b | Secret (JOI14_secret) | C++17 | 617 ms | 9900 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;
#include "secret.h"
typedef long double ld;
typedef long long ll;
ll niz[1005];
ll res[1005][1005];
int n;
int fajnd(int l, int r, int tl, int tr){
if(l > tr || tl > r) return -1;
int mid = (l+r)/2;
if(l <= tl && tr <= r && tl <= mid && r >= mid+1) return mid;
int x = fajnd(l, mid, tl, tr);
if(x == -1) return fajnd(mid+1, r, tl, tr);
}
void process(int l, int r){
int mid = (l+r)/2;
if(l == r) return;
res[mid][mid] = niz[mid];
res[mid+1][mid+1] = niz[mid+1];
for(ll j=mid-1; j>=l; j--){
res[j][mid] = Secret(niz[j], res[j+1][mid]);
}
for(ll j=mid+2; j<=r; j++){
res[mid+1][j] = Secret(res[mid+1][j-1], niz[j]);
}
process(l, mid);
process(mid+1, r);
}
void Init(int N, int A[]){
n = N;
for(ll i=0; i<N; i++) niz[i] = A[i];
process(0, n-1);
}
int Query(int L, int R){
if(L == R) return niz[L];
if(R == L+1) return Secret(niz[L], niz[R]);
int i = fajnd(0, n-1, L, R);
return Secret(res[L][i], res[i+1][R]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |