답안 #297781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297781 2020-09-11T22:24:18 Z Osama_Alkhodairy 비밀 (JOI14_secret) C++17
100 / 100
530 ms 4600 KB
#include <bits/stdc++.h>
#include "secret.h"
//~ #include "grader.cpp"
using namespace std;

const int NN = 1001;
const int K = 11;

int n, v[K][NN];
vector <int> a;

void build(int l, int r, int level){
    int mid = (l + r) / 2;
    v[level][mid] = a[mid];
    if(r <= l) return;
    v[level][mid + 1] = a[mid + 1];
    for(int i = mid - 1 ; i >= l ; i--){
        v[level][i] = Secret(a[i], v[level][i + 1]);
    }
    for(int i = mid + 2 ; i <= r ; i++){
        v[level][i] = Secret(v[level][i - 1], a[i]);
    }
    build(l, mid, level + 1);
    build(mid + 1, r, level + 1);
}
int query(int l, int r, int s, int e, int level){
    int mid = (l + r) / 2;
    if(s <= mid && mid <= e){
        if(e == mid) return v[level][s];
        if(s == mid + 1) return v[level][e];
        return Secret(v[level][s], v[level][e]);
    }
    else if(e < mid) return query(l, mid, s, e, level + 1);
    return query(mid + 1, r, s, e, level + 1);
}
void Init(int N, int A[]) {
    n = N;
    a.resize(n);
    for(int i = 0 ; i < n ; i++){
        a[i] = A[i];
    }
    build(0, n - 1, 0);
}
int Query(int L, int R) {
    return query(0, n - 1, L, R, 0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 2516 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 148 ms 2552 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 149 ms 2552 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 530 ms 4388 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 521 ms 4436 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 524 ms 4472 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 523 ms 4488 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 525 ms 4600 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 530 ms 4472 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 527 ms 4440 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1