#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1005];
int val[1005][1005];
vector<int> v[1005];
int maxid = 0;
// 4: 0 1 2 3
void rek(int l, int r, int d) {
maxid = max(maxid, d);
if (l+1 == r) {
v[d].push_back(l);
val[l][l] = a[l];
return;
}
int mid = (l+r)/2;
int tren = a[mid-1];
for (int j = mid-2; j >= l; j--) {
tren = Secret(tren, a[j]);
val[j][mid-1] = tren;
}
tren = a[mid];
for (int j = mid+1; j < r; j++) {
tren = Secret(tren, a[j]);
val[mid][j] = tren;
}
v[d].push_back(mid);
rek(l, mid, d+1);
rek(mid, r, d+1);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; i++) a[i] = A[i];
rek(0, n, 0);
}
int Query(int l, int r) {
for (int i = 0; i <= maxid; i++) {
for (int j = 0; j < v[i].size(); j++) {
if (l <= v[i][j] && v[i][j] <= r) {
if (l <= v[i][j]-1) return Secret(val[l][v[i][j]-1], val[v[i][j]][r]);
else return val[v[i][j]][r];
}
}
}
}
Compilation message
secret.cpp: In function 'int Query(int, int)':
secret.cpp:46:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int j = 0; j < v[i].size(); j++) {
| ~~^~~~~~~~~~~~~
secret.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type]
53 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
123 ms |
4356 KB |
Wrong Answer: Query(113, 206) - expected : 536899947, actual : 50471211. |
2 |
Incorrect |
127 ms |
4396 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 311474560. |
3 |
Incorrect |
125 ms |
4432 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 162768982. |
4 |
Incorrect |
446 ms |
8160 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 858309235. |
5 |
Incorrect |
454 ms |
8224 KB |
Wrong Answer: Query(587, 915) - expected : 752404486, actual : 957013316. |
6 |
Incorrect |
449 ms |
8136 KB |
Wrong Answer: Query(258, 261) - expected : 706122386, actual : 570946457. |
7 |
Incorrect |
458 ms |
8240 KB |
Wrong Answer: Query(84, 976) - expected : 742463504, actual : 675449873. |
8 |
Incorrect |
502 ms |
8256 KB |
Wrong Answer: Query(58, 987) - expected : 20022464, actual : 273091792. |
9 |
Incorrect |
504 ms |
8252 KB |
Wrong Answer: Query(33, 967) - expected : 676869696, actual : 827853577. |
10 |
Incorrect |
441 ms |
8172 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 337854787. |