답안 #165330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
165330 2019-11-26T11:56:18 Z jovan_b 비밀 (JOI14_secret) C++17
100 / 100
638 ms 9880 KB
#include <bits/stdc++.h>
using namespace std;
#include "secret.h"
typedef long double ld;
typedef long long ll;

ll niz[1005];
ll res[1005][1005];
ll n;

ll fajnd(ll l, ll r, ll trl, ll trr){
    if(r-l <= 1) return -1;
    ll mid = (l+r)/2;
    if(l <= trl && trr <= r && trl <= mid && trr >= mid+1) return mid;
    ll x = fajnd(l, mid, trl, trr);
    if(x != -1) return x;
    return fajnd(mid+1, r, trl, trr);
}

void process(ll l, ll r){
    ll i = (l+r)/2;
  	if(i+1 > r || i < l) return;
    res[i][i] = niz[i];
    res[i+1][i+1] = niz[i+1];
    for(ll j=i-1; j>=l; j--){
        res[j][i] = Secret(niz[j], res[j+1][i]);
    }
    for(ll j=i+2; j<=r; j++){
        res[i+1][j] = Secret(res[i+1][j-1], niz[j]);
    }
    process(l, i);
    process(i+1, r);
}

void Init(int N, int A[]){
    n = N;
    for(ll i=0; i<N; i++) niz[i] = A[i];
    process(0, n-1);
}

int Query(int L, int R){
    if(L == R) return niz[L];
    if(R == L+1) return Secret(niz[L], niz[R]);
    ll i = fajnd(0, n-1, L, R);
    return Secret(res[L][i], res[i+1][R]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 4864 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 179 ms 4872 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 178 ms 4896 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 638 ms 9660 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 618 ms 9720 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 636 ms 9720 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 611 ms 9684 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 616 ms 9632 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 616 ms 9636 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 623 ms 9880 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1