#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
#define MAX 1010
struct range {
ll x, y;
ll v;
};
vector<range> vv;
vector<ll> a;
ll arr1[MAX][MAX];
ll arr2[MAX][MAX];
void init(ll low, ll high) {
if (low >= high) return;
ll mid = (low + high) / 2;
vv.push_back({ low, high, mid });
init(low, mid);
init(mid + 1, high);
}
void Init(int N, int A[]) {
init(1, N);
ll i, j;
ll mid;
a.resize(N + 1);
for (i = 0; i < N; i++) a[i + 1] = A[i];
for (i = 0; i < vv.size(); i++) {
mid = vv[i].v;
arr1[mid][mid] = A[mid - 1];
for (j = mid - 1; j >= vv[i].x; j--) arr1[mid][j] = Secret(A[j - 1], arr1[mid][j + 1]);
if (mid + 1 <= vv[i].y) arr2[mid][mid + 1] = A[mid];
for (j = mid + 2; j <= vv[i].y; j++) arr2[mid][j] = Secret(arr2[mid][j - 1], A[j - 1]);
}
}
int Query(int L, int R) {
ll i;
L++;
R++;
if (L == R) return a[L];
if (R - L == 1) return Secret(a[L], a[R]);
ll m = 0;
ll aa;
aa = 0;
for (i = 0; i < vv.size(); i++) {
if (vv[i].x <= L && R <= vv[i].y && L <= vv[i].v && vv[i].v <= R) {
if (m < vv[i].y - vv[i].x) {
m = vv[i].y - vv[i].x;
aa = i;
}
}
}
if (vv[aa].v == L) return Secret(a[L], arr2[vv[aa].v][R]);
if (vv[aa].v == R) return arr1[vv[aa].v][L];
return Secret(arr1[vv[aa].v][L], arr2[vv[aa].v][R]);
}
Compilation message
secret.cpp: In function 'void Init(int, int*)':
secret.cpp:31:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<range>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (i = 0; i < vv.size(); i++) {
| ~~^~~~~~~~~~~
secret.cpp: In function 'int Query(int, int)':
secret.cpp:49:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<range>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (i = 0; i < vv.size(); i++) {
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
6508 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
150 ms |
6636 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
164 ms |
6528 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
521 ms |
12268 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
517 ms |
12272 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
519 ms |
12304 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
521 ms |
12304 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
524 ms |
12256 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
534 ms |
12268 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
524 ms |
12304 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |