답안 #978702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978702 2024-05-09T14:11:11 Z chautanphat 비밀 (JOI14_secret) C++14
100 / 100
361 ms 4568 KB
#include "secret.h"

const int maxn = 1e3;
int mask[maxn], a[maxn];
long long ans[10][maxn];

void dnc(int l, int r, int level = 0)
{
	if (l == r) return;
	int mid = (l + r) / 2;
   	ans[level][mid] = a[mid];
    for (int i = mid - 1; i >= l; i--)
		ans[level][i] = Secret(a[i], ans[level][i + 1]);
    ans[level][mid + 1] = a[mid + 1];
    for (int i = mid + 2; i <= r; i++)
        ans[level][i] = Secret(ans[level][i - 1], a[i]);
    dnc(l, mid, level + 1);
    dnc(mid + 1, r, level + 1);
    for (int i = mid + 1; i <= r; i++) mask[i] |= 1 << level;
}

void Init(int N, int A[])
{
	for (int i = 0; i < N; i++) a[i] = A[i];
	dnc(0, N - 1);
}

int Query(int L, int R)
{
	if (L == R) return a[L];
	int level = __builtin_ctz(mask[L] ^ mask[R]);
	return Secret(ans[level][L], ans[level][R]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 3668 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 105 ms 3764 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 101 ms 3664 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 357 ms 4548 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 355 ms 4568 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 356 ms 4436 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 355 ms 4556 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 359 ms 4428 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 357 ms 4492 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 361 ms 4416 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1