답안 #1057279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057279 2024-08-13T16:17:00 Z fryingduc 비밀 (JOI14_secret) C++17
100 / 100
276 ms 8300 KB
#include "bits/stdc++.h"
using namespace std;

#ifndef duc_debug
#include "secret.h"
#endif

const int maxn = 1e3 + 3;
int n, a[maxn]; 
int pref[maxn][maxn];

void solve(int l, int r) {
    int mid = (l + r) / 2;
    pref[mid][mid] = a[mid];
    pref[mid + 1][mid + 1] = a[mid + 1];
    for(int i = mid + 2; i <= r; ++i) {
        pref[mid + 1][i] = Secret(pref[mid + 1][i - 1], a[i]);
    }
    for(int i = mid - 1; i >= l; --i) {
        pref[mid][i] = Secret(a[i], pref[mid][i + 1]);
    }
    if(l < mid) {
        solve(l, mid);
    }
    if(mid + 1 < r) {
        solve(mid + 1, r);
    }
}
void Init(int _n, int _a[]) { 
    n = _n;
    for(int i = 0; i < n; ++i) {
        a[i] = _a[i];
    }
    solve(0, n - 1);
}
int Query(int l, int r) {
    int x = 0, y = n - 1;
    while(x < y) {
        int mid = (x + y) / 2;
        if(l <= mid and mid < r) {
            return Secret(pref[mid][l], pref[mid + 1][r]);
        }
        else if(mid == r) return pref[mid][l];
        else if(mid < l) x = mid + 1;
        else y = mid;
    }
    return pref[x][x];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 6764 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 73 ms 6748 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 80 ms 6624 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 264 ms 8284 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 271 ms 8272 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 276 ms 8284 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 271 ms 8296 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 266 ms 8216 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 265 ms 8300 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 276 ms 8284 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1