#include "secret.h"
#include <map>
#include <utility>
using namespace std;
typedef pair<int, int> ip;
int a[1001], n;
map<ip, int> d;
int qry(int l, int r, int L, int R) {
if (L == R) return a[L];
int mid = (l + r) / 2;
if (R < mid) return qry(l, mid, L, R);
else if (L >= mid) return qry(mid, r, L, R);
else {
return Secret(d[ip(L, mid - 1)], d[ip(mid, R)]);
}
}
int Query(int L, int R) {
return qry(0, n, L, R);
}
void go(int l, int r) {
if (l + 1 == r) return;
int mid = (l + r) / 2;
int cur = a[mid - 1];
for (int i = mid - 2; i >= l; i--) {
cur = Secret(a[i], cur);
d[ip(i, mid - 1)] = cur;
}
cur = a[mid];
for (int i = mid + 1; i < r; i++) {
cur = Secret(cur, a[i]);
d[ip(mid, i)] = cur;
}
go(l, mid);
go(mid, r);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; i++) {
a[i] = A[i];
d[ip(i, i)] = a[i];
}
go(0, n);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
171 ms |
2552 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
182 ms |
2668 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
174 ms |
2816 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
615 ms |
5096 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
598 ms |
5100 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
603 ms |
5196 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
609 ms |
5196 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
642 ms |
5196 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
652 ms |
5196 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
631 ms |
5196 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |