#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';
// }
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
98 ms |
4692 KB |
Wrong Answer: Query(222, 254) - expected : 34031541, actual : 809782271. |
2 |
Incorrect |
98 ms |
4688 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 68749376. |
3 |
Incorrect |
103 ms |
4768 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 136349820. |
4 |
Incorrect |
370 ms |
12120 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 650789536. |
5 |
Incorrect |
368 ms |
12356 KB |
Wrong Answer: Query(587, 915) - expected : 752404486, actual : 377506838. |
6 |
Incorrect |
375 ms |
12368 KB |
Wrong Answer: Query(738, 741) - expected : 983692994, actual : 61461050. |
7 |
Incorrect |
374 ms |
12192 KB |
Wrong Answer: Query(84, 976) - expected : 742463504, actual : 687550570. |
8 |
Incorrect |
370 ms |
12152 KB |
Wrong Answer: Query(58, 987) - expected : 20022464, actual : 145923264. |
9 |
Incorrect |
372 ms |
12416 KB |
Wrong Answer: Query(33, 967) - expected : 676869696, actual : 18757135. |
10 |
Incorrect |
365 ms |
12368 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 70590726. |