답안 #698046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698046 2023-02-12T06:03:46 Z badont 비밀 (JOI14_secret) C++17
100 / 100
440 ms 4776 KB
#include "secret.h"
#include <bits/stdc++.h>

using namespace std;
using pii = pair<int,int>;

struct Tree {
	vector<vector<int>> left, right;
	int n;

	void init(int n, const vector<int>& data) {
		this->n = n;
		left.resize(4 * n + 5);
		right.resize(4 * n + 5);

		auto dfs = [&](auto dfs, int z, int l, int r) -> void {
			int m = (l + r) >> 1;

			left[z].resize(m - l + 1);
			right[z].resize(r - m);

			if (l == r) {
				left[z][0] = data[l];
				return;
			}

			left[z][0] = data[m];
			for (int i = m - 1, idx = 1; i >= l; i--, idx++) {
				left[z][idx] = Secret(data[i], left[z][idx - 1]);
			}
			right[z][0] = data[m + 1];
			for (int i = m + 2, idx = 1; i <= r; i++, idx++) {
				right[z][idx] = Secret(right[z][idx - 1], data[i]);
			}

			dfs(dfs, 2 * z, l, m);
			dfs(dfs, 2 * z + 1, m + 1, r);
		};
		dfs(dfs, 1, 0, n - 1);
	}

	int query(int z, int l, int r, int ql, int qr) {
		int m = (l + r) >> 1;

		if (l == r) {
			return left[z][0];
		}

		if (qr <= m) return query(2 * z, l, m, ql, qr);
		if (ql >= m + 1) return query(2 * z + 1, m + 1, r, ql, qr);

		int idx1 = m - ql, idx2 = qr - (m + 1);
		if (ql == qr) return left[z][idx1];
		return Secret(left[z][idx1], right[z][idx2]);
	}

	int query(int ql, int qr) { return query(1, 0, n - 1, ql, qr); }
} tree;

void Init(int N, int A[]) {
	vector<int> a(N);
	for (int i = 0; i < N; i++)
		a[i] = A[i];

	tree.init(N, a);
}

int Query(int L, int R) {
	return tree.query(L, R);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 2440 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 138 ms 2420 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 123 ms 2564 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 424 ms 4504 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 422 ms 4776 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 440 ms 4552 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 423 ms 4588 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 431 ms 4472 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 425 ms 4684 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 423 ms 4548 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1