Submission #565533

#TimeUsernameProblemLanguageResultExecution timeMemory
565533ac2huSecret (JOI14_secret)C++14
100 / 100
493 ms12092 KiB
#include "secret.h"
#include<bits/stdc++.h>
using namespace std;
const int _N = 1e3 + 1;
int RR[_N][_N];// right[i][j] = query(j, i)
int LL[_N][_N]; // left[i][j] = query(i, j)
vector<int> temp;
int a[_N];
int n;
int c = 0;
void build(int l,int r){
    if(l == r)return;
    if(l + 1 == r)return;
    int mid = (l + r)/2; 
    assert(mid < r && l <= mid);
    temp.push_back(mid);
    RR[mid + 1][mid] = a[mid + 1];
    for(int i = mid + 2;i<=r;i++){
        RR[i][mid] = Secret(RR[i - 1][mid],  a[i]);
    }
    LL[mid][mid] = a[mid];
    for(int i = mid - 1;i>=l;i--){
        LL[i][mid] = Secret(a[i], LL[i + 1][mid]);
    }
    build(l, mid);
    build(mid + 1, r);
}
void Init(int N, int A[]) {
    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];
    }
    else if(L + 1 == R)
        return Secret(a[L], a[R]);
    else{
        for(auto e : temp){
            if(L <= e && e < R)return Secret(LL[L][e], RR[R][e]);
        }
        assert(false);
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...