Submission #794030

# Submission time Handle Problem Language Result Execution time Memory
794030 2023-07-26T08:53:06 Z acatmeowmeow Secret (JOI14_secret) C++11
100 / 100
389 ms 4408 KB
#include "secret.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 1e3;
int arr[N + 5], dat[15][N + 5], mask[N + 5];

void build(int level, int l, int r) {
	if (l == r) return;
	int m = (l + r)/2;
	dat[level][m] = arr[m];
	for (int i = m - 1; i >= l; i--) dat[level][i] = Secret(arr[i], dat[level][i + 1]); 
	dat[level][m + 1] = arr[m + 1];
	for (int i = m + 2; i <= r; i++) dat[level][i] = Secret(dat[level][i - 1], arr[i]);
	for (int i = m + 1; i <= r; i++) mask[i] ^= (1ll << level);
	build(level + 1, l, m);
	build(level + 1, m + 1, r);
}

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

int Query(int L, int R) {
	if (L == R) return arr[L];
	int level = __builtin_ctzll(mask[L] ^ mask[R]);
	return Secret(dat[level][L], dat[level][R]);
}
# Verdict Execution time Memory Grader output
1 Correct 116 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 111 ms 2412 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 108 ms 2432 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 382 ms 4348 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 379 ms 4336 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 382 ms 4312 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 388 ms 4404 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 384 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 389 ms 4312 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 381 ms 4408 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1