# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
959810 | irmuun | Secret (JOI14_secret) | C++17 | 365 ms | 11704 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>
#include "secret.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
const ll maxn=1e3+5;
int n;
vector<pair<int,int>>v;
int pre[maxn][maxn],suf[maxn][maxn];
int a[maxn];
void build(int l,int r){
if(l+1>=r) return;
int mid=(l+r)/2;
suf[mid][mid]=a[mid];
for(int i=mid-1;i>=l;i--){
suf[mid][i]=Secret(a[i],suf[mid][i+1]);
}
pre[mid+1][mid+1]=a[mid+1];
for(int i=mid+2;i<=r;i++){
pre[mid+1][i]=Secret(pre[mid+1][i-1],a[i]);
}
build(l,mid);
build(mid+1,r);
}
int ask(int l,int r,int L,int R){
int mid=(l+r)/2;
if(R<=mid){
return ask(l,mid,L,R);
}
if(L>=mid+1){
return ask(mid+1,r,L,R);
}
return Secret(suf[mid][L],pre[mid+1][R]);
}
void Init(int N,int A[]){
n=N;
for(int i=0;i<n;i++){
a[i]=A[i];
}
build(0,n-1);
}
int Query(int l,int r){
if(l==r){
return a[l];
}
if(l+1==r){
return Secret(a[l],a[r]);
}
return ask(0,n-1,l,r);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |