#include "secret.h"
#include<bits/stdc++.h>
#define ll long long
#define FOR(i, a, b) for(int i = a; i <= b;i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define TASKNAME "secret"
using namespace std;
const int MAXN = 1004;
int P[20][MAXN], mask[MAXN], a[MAXN];
int n, q;
void DnC(int l, int r, int lev){
if (l == r){
return;
}
int mid = (l + r) >> 1;
P[lev][mid] = a[mid];
P[lev][mid + 1] = a[mid + 1];
// printf("RANGE %lld %lld\n", l, r);
FORD(i, mid - 1, l){
P[lev][i] = Secret(a[i], P[lev][i + 1]);
}
// FORD(i, mid, l){
// printf("%lld ", P[lev][i]);
// }
// printf("\n");
FOR(i, mid + 2, r){
P[lev][i] = Secret(P[lev][i - 1], a[i]);
}
// FOR(i, mid + 1, r){
// printf("%lld ", P[lev][i]);
// }
// printf("\n");
FOR(i, mid + 1, r) mask[i] ^= (1LL << lev);
DnC(l, mid, lev + 1);
DnC(mid + 1, r, lev + 1);
}
void Init(int N, int A[]) {
FOR(i, 0, N - 1){
a[i] = A[i];
}
DnC(0, N - 1, 0);
}
int Query(int L, int R) {
if (L == R) return a[L];
else{
int bit = __builtin_ctz(mask[L] ^ mask[R]);
// printf("%lld %lld %lld\n", bit, P[bit][L], P[bit][R]);
return Secret(P[bit][L], P[bit][R]);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
2728 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
85 ms |
2648 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
87 ms |
2648 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
309 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
308 ms |
4432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
308 ms |
4432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
307 ms |
4432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
314 ms |
4432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
308 ms |
4432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
310 ms |
4384 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |