답안 #914345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914345 2024-01-21T17:10:14 Z sverma22 비밀 (JOI14_secret) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
// #include "secret.h"

using namespace std; 

// #define int int64_t

struct Info {
    int L, R, M; 
    vector<int> pre; 
    vector<int> suff; 
}; 

map<int, Info> info_map; // layer ... 
vector<int> a; 
int N; 

// int Secret(int x, int y) {
//     return min(x, y); 
// }

void dvc(int l, int r, int layer = 1) {
    if(l == r) {
        return; 
    }

    int m = (l + r) / 2; 
    info_map[layer].pre.resize(N); 
    info_map[layer].suff.resize(N); // (r - (m + 1) + 1)

    info_map[layer].pre[m] = a[m]; 
    for(int i = m - 1; i >= l; i--) info_map[layer].pre[i] = Secret(a[i], info_map[layer].pre[i + 1]);

    info_map[layer].suff[m + 1] = a[m + 1]; 
    for(int i = m + 2; i <= r; i++) info_map[layer].suff[i] = Secret(a[i], info_map[layer].suff[i - 1]); 

    info_map[layer].L = l; 
    info_map[layer].R = r; 
    info_map[layer].M = m; 

    dvc(l, m, 2 * layer); 
    dvc(m + 1, r, 2 * layer + 1); 
}


void Init(int n, int A[]) {
    N = n; 
    a.resize(n); 
    for(int i = 0; i < n; i++) a[i] = A[i]; 

    dvc(0, n - 1); 
}



int Query(int L, int R) {
    // FIND THE CORRECT LAYER 
    if(L == R) return a[L]; 
    int layer = 1; 
    while(true) {
        if(L <= info_map[layer].M && info_map[layer].M < R) {
            return Secret(info_map[layer].pre[L], info_map[layer].suff[R]); 
        } else if(L > info_map[layer].M) {
            layer = 2 * layer + 1; // go to right child
        } else {
            layer = 2 * layer; // go to left child ... 
        }
    }

    return 0; 
}


// signed main() {
//     int A[8] = {2, 4, 3, 1, 7, 6, 2, 4}; 
//     Init(8, A); 

//     for(int i = 1; i <= 7; i++) {
//         cout << info_map[i].L << ' ' << info_map[i].R << '\n';
//     }

//     vector<pair<int, int> > qs = {{0, 0}, {0, 1}, {1, 2}, {3, 5}, {5, 7}, {2, 5}}; 

//     for(auto [a, b] : qs) {
//         cout << Query(a, b) << '\n';
//     }

// }

Compilation message

secret.cpp: In function 'void dvc(int, int, int)':
secret.cpp:32:62: error: 'Secret' was not declared in this scope
   32 |     for(int i = m - 1; i >= l; i--) info_map[layer].pre[i] = Secret(a[i], info_map[layer].pre[i + 1]);
      |                                                              ^~~~~~
secret.cpp:35:63: error: 'Secret' was not declared in this scope
   35 |     for(int i = m + 2; i <= r; i++) info_map[layer].suff[i] = Secret(a[i], info_map[layer].suff[i - 1]);
      |                                                               ^~~~~~
secret.cpp: In function 'int Query(int, int)':
secret.cpp:62:20: error: 'Secret' was not declared in this scope
   62 |             return Secret(info_map[layer].pre[L], info_map[layer].suff[R]);
      |                    ^~~~~~