답안 #838602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838602 2023-08-27T12:44:58 Z Chal1shkan 비밀 (JOI14_secret) C++14
100 / 100
412 ms 4360 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
# define nl "\n"
const int maxn = 1e3 + 3;
int tl[10][maxn];
int tr[10][maxn];
int a[maxn], n, ans;
void doit (int l, int r, int d) {
	if (l >= r) return;
//	cout << "vot " << l << ' ' << r << ' ' << d << '\n';
	int mid = (l + r) >> 1;
	tl[d][mid] = a[mid];
	for (int i = mid - 1; i >= l; --i) {
		tl[d][i] = Secret(a[i], tl[d][i + 1]);
	}
//	cout << "tl side" << nl;
//	for (int i = mid; i >= l; --i) {
//		cout << tl[d][i] << ' ';
//	}
//	cout << nl;
	tr[d][mid + 1] = a[mid + 1];
	for (int i = mid + 2; i <= r; ++i) {
		tr[d][i] = Secret(tr[d][i - 1], a[i]);
	}
//	cout << "tr side" << nl;
//	for (int i = mid + 1; i <= r; ++i) {
//		cout << tr[d][i] << ' ';
//	}
//	cout << nl;
	doit(l, mid, d + 1);
	doit(mid + 1, r, d + 1);
}
void solve (int L, int R, int l, int r, int d) {
	if (l >= r) {
		return;
	}
	int mid = (l + r) >> 1;
	if (l <= L && L <= mid && mid + 1 <= R && R <= r) {
		ans = Secret(tl[d][L], tr[d][R]);
		return;
	}
	solve (L, R, l, mid, d + 1);
	solve (L, R, mid + 1, r, d + 1);
}
void Init(int N, int A[]) {
	n = N;
	for (int i = 0; i < N; ++i) {
		a[i] = A[i];
	}
	doit (0, n - 1, 1);
}
int Query(int L, int R) {
	if (L == R) {
		return a[L];
	}
	ans = 0;
	solve (L, R, 0, n - 1, 1);
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 2340 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 115 ms 2332 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 122 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 392 ms 4360 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 396 ms 4268 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 412 ms 4352 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 381 ms 4300 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 404 ms 4328 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 392 ms 4360 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 386 ms 4260 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1