#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 200005
int ranges[1005][1005];
int n;
void build(int l, int r, int A[]) {
if (l == r) {
ranges[l][l] = A[l];
return ;
}
int mid1 = (l+r)/2;
int mid2 = mid1+1;
ranges[mid1][mid1] = A[mid1];
ranges[mid2][mid2] = A[mid2];
for (int i = mid1-1; i >= l; i--)
ranges[i][mid1] = Secret(A[i], ranges[i+1][mid1]);
for (int i = mid2+1; i <= r; i++)
ranges[mid2][i] = Secret(ranges[mid2][i-1], A[i]);
build(l, mid1, A);
build(mid2, r, A);
}
void Init(int N, int A[]) {
build(0, N-1, A);
n = N;
}
int Query(int L, int R) {
int now_l = 0;
int now_r = n-1;
while (now_l <= now_r) {
int mid1 = (now_l+now_r)/2;
int mid2 = (now_l+now_r)/2+1;
if (L <= mid1 && R >= mid2)
return Secret(ranges[L][mid1], ranges[mid2][R]);
else if (L == mid2 || R == mid1)
return ranges[L][R];
if (L >= mid2)
now_l = mid2;
else
now_r = mid1;
}
}
Compilation message
secret.cpp: In function 'int Query(int, int)':
secret.cpp:54:1: warning: control reaches end of non-void function [-Wreturn-type]
54 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
4300 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
111 ms |
4324 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
110 ms |
4316 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
397 ms |
8120 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
391 ms |
8324 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
386 ms |
8176 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
386 ms |
8248 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
386 ms |
8128 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
387 ms |
8172 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
386 ms |
8180 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |