답안 #1055836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055836 2024-08-13T05:57:26 Z trandangquang 비밀 (JOI14_secret) C++14
100 / 100
290 ms 4692 KB
#include <bits/stdc++.h>
#include "secret.h"

#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define eb emplace_back
#define all(a) (a).begin(), (a).end()

using namespace std;

int n, a[1005], cnt;
vector <int> ops[4005];

//int Secret(int X, int Y) {
//    /// program's
//    ++cnt;
//    return X*Y;
//}

void build(int id=1, int l=0, int r=n-1) {
    if(l == r) {
        ops[id] = {a[l]};
        return;
    }

//    cout<<l<<" "<<r<<'\n';
    int mid = (l + r) >> 1;

    ops[id] = {a[mid]};
    FORD(i, mid-1, l) ops[id].eb(Secret(a[i], ops[id].back()));

    reverse(all(ops[id]));

    ops[id].eb(a[mid+1]);
    FOR(i, mid+2, r) ops[id].eb(Secret(ops[id].back(), a[i]));

//    if(l == 4 && r == 7) {
//        cout << mid << '\n';
//        for(int i:ops[id]) cout << i << " ";
//        cout << '\n';
//    }

    build(id<<1, l, mid);
    build(id<<1|1, mid+1, r);
}

void Init(int N, int A[]) {
    n = N;
    FOR(i, 0, N-1) {
        a[i] = A[i];
    }
    build();
}

int get(int L, int R, int id=1, int l=0, int r=n-1) {
    int mid = (l+r) >> 1;

    if(R==mid) return ops[id][L-l];
    if(L==mid+1) return ops[id][R-l];
    if(L<=mid && mid+1<=R) return Secret(ops[id][L-l], ops[id][R-l]);

    if(R<mid) return get(L, R, id<<1, l, mid);
    return get(L, R, id<<1|1, mid+1, r);
}

int Query(int L, int R) {
    return get(L, R);
}

//int main() {
//    int b[] = {1,2,0,5,4};
//    Init(5, b);
////    cout<<cnt<<'\n';
//    cout<<Query(4,4)<<'\n';
//}
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 2476 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 71 ms 2696 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 93 ms 2640 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 275 ms 4692 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 263 ms 4604 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 286 ms 4484 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 279 ms 4436 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 290 ms 4496 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 269 ms 4584 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 269 ms 4584 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1