#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <deque>
#include <queue>
#include <tuple>
#include <cmath>
#include <cctype>
#include <stack>
#include <cassert>
#include "secret.h"
using namespace std;
using ll = long long;
int dat[11][1000];
int mask[1000];
int a[1000];
void build(int l, int r, int A[], int lev) {
if (l == r) return;
int mid = (l+r)/2;
dat[lev][mid] = A[mid]; dat[lev][mid+1] = A[mid+1];
for (int i = mid-1; i >= l; i--) dat[lev][i] = Secret(A[i], dat[lev][i+1]);
for (int i = mid+2; i <= r; i++) dat[lev][i] = Secret(dat[lev][i-1], A[i]);
for (int i = mid+1; i <= r; i++) mask[i] ^= 1<<lev;
build(l, mid, A, lev+1); build(mid+1, r, A, lev+1);
}
void Init(int N, int A[]) {
build(0, N-1, A, 0);
for (int i = 0; i < N; i++) a[i] = A[i];
}
int Query(int L, int R) {
if (L == R) return a[L];
int lev = __builtin_ctz(mask[L]^mask[R]);
return Secret(dat[lev][L], dat[lev][R]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
2436 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
136 ms |
2480 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
131 ms |
2408 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
509 ms |
4320 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
488 ms |
4412 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
490 ms |
4404 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
461 ms |
4376 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
512 ms |
4392 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
481 ms |
4280 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
501 ms |
4360 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |