Submission #49485

# Submission time Handle Problem Language Result Execution time Memory
49485 2018-05-29T15:45:26 Z Anai Secret (JOI14_secret) C++14
100 / 100
794 ms 21500 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;

const int NMAX = 1024;

int ql, qr, n, *v;

int tree_l[4 * NMAX][NMAX], tree_r[4 * NMAX][NMAX];


static void build(int nod, int l, int r) {
	if (l == r) {
		tree_l[nod][l] = tree_r[nod][r] = v[l];
		return; }

	int mid = (l + r) / 2;

	build(2 * nod, l, mid);
	build(2 * nod + 1, mid + 1, r);

	tree_l[nod][mid] = v[mid];
	tree_r[nod][mid + 1] = v[mid + 1];

	for (int i = mid - 1; i >= l; --i)
		tree_l[nod][i] = Secret(v[i], tree_l[nod][i + 1]);
	for (int i = mid + 2; i <= r; ++i)
		tree_r[nod][i] = Secret(tree_r[nod][i - 1], v[i]); }

static int query(int nod, int l, int r) {
	if (l == r) return v[l];

	const int mid = (l + r) / 2;
	if (ql <= mid && mid < qr)
		return Secret(tree_l[nod][ql], tree_r[nod][qr]);
	return ql <= mid ? query(2 * nod, l, mid) : query(2 * nod + 1, mid + 1, r); }


void Init(int N, int A[]) {
	tie(n, v) = tie(N, A);
	build(1, 0, n - 1); }

int Query(int L, int R) {
	tie(ql, qr) = tie(L, R);
	return query(1, 0, n - 1); }
# Verdict Execution time Memory Grader output
1 Correct 187 ms 10616 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 191 ms 10928 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 198 ms 11048 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 657 ms 20856 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 665 ms 20900 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 692 ms 21140 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 633 ms 21288 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 666 ms 21288 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 794 ms 21304 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 618 ms 21500 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1