# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
54651 | red1108 | Secret (JOI14_secret) | C++17 | 738 ms | 4704 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 <stdio.h>
#include <algorithm>
#include "secret.h"
using namespace std;
int seg[10000], si=1;
void Init(int N, int A[])
{
int input[2000],i;
while(si<N) si*=2;
for(i=N;i>=1;i--)
{
input[i]=A[i-1];
}
for(i=1;i<=si*4;i++) seg[i]=123456789;
for(i=si+N-1;i>=si;i--)
{
seg[i]=input[i-si+1];
}
for(i=si-1;i>=1;i--)
{
if(seg[i*2]==123456789)seg[i]=123456789;
else if(seg[i*2+1]==123456789)seg[i]=seg[i*2];
else seg[i]=Secret(seg[i*2],seg[i*2+1]);
}
}
int query(int x, int l, int r, int s, int e)
{
int mid, left, right;
if(r<s||l>e||l>r) return 123456789;
if(s<=l&&r<=e) return seg[x];
left=query(x*2, l,(l+r)/2,s,e);
right=query(x*2+1, ((l+r)/2)+1,r, s, e);
if(left==123456789&&right==123456789) return 123456789;
else if(right==123456789) return left;
else if(left==123456789) return right;
else return Secret(left, right);
}
int Query(int L, int R)
{
L++;
R++;
return query(1,1,si,L, R);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |