답안 #153490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153490 2019-09-14T11:00:57 Z georgerapeanu 비밀 (JOI14_secret) C++11
100 / 100
611 ms 4504 KB
#include "secret.h"

using namespace std;

int stuff[11][1005];
int global_n;

void build(int stage,int st,int dr,int a[]){

    if(st == dr){
        stuff[stage][st] = a[st];
        return ;
    }

    int mid = (st + dr) / 2;

    stuff[stage][mid] = a[mid];
    stuff[stage][mid + 1] = a[mid + 1];

    for(int i = mid - 1;i >= st;i--){
        stuff[stage][i] = Secret(a[i],stuff[stage][i + 1]);
    }
    
    for(int i = mid + 2;i <= dr;i++){
        stuff[stage][i] = Secret(stuff[stage][i - 1],a[i]);
    }

    build(stage + 1,st,mid,a);
    build(stage + 1,mid + 1,dr,a);
}

int query(int stage,int st,int dr,int l,int r){
    
    int mid = (st + dr) / 2;

    if(l <= mid && mid <= r){
        if(r == mid){
            return stuff[stage][l];
        }
        return Secret(stuff[stage][l],stuff[stage][r]);
    }
    else if(mid < l){
        return query(stage + 1,mid + 1,dr,l,r);
    }
    else{
        return query(stage + 1,st,mid,l,r);
    }
}

void Init(int n, int a[]) {
    global_n = n;
    build(0,0,n - 1,a);
}

int Query(int l, int r) {
    return query(0,0,global_n - 1,l,r);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 2520 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 166 ms 2404 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 166 ms 2424 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 571 ms 4420 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 581 ms 4476 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 611 ms 4388 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 580 ms 4380 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 576 ms 4376 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 576 ms 4276 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 582 ms 4504 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1