Submission #565533

# Submission time Handle Problem Language Result Execution time Memory
565533 2022-05-21T04:38:12 Z ac2hu Secret (JOI14_secret) C++14
100 / 100
493 ms 12092 KB
#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 time Memory Grader output
1 Correct 131 ms 6356 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 138 ms 6316 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 133 ms 6352 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 448 ms 12080 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 461 ms 12068 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 493 ms 12072 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 462 ms 12092 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 473 ms 12088 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 467 ms 12044 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 474 ms 12004 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1