Submission #52530

# Submission time Handle Problem Language Result Execution time Memory
52530 2018-06-26T06:48:56 Z 크리(#1967) Secret (JOI14_secret) C++11
100 / 100
652 ms 4684 KB
#include "secret.h"

int n, a[1010];
int u[10][1010];

void go(int d, int l, int r)
{
	if (l == r) return;

	int m = (l + r) / 2;

	u[d][m] = a[m];
	for (int i = m-1; i >= l; i--) {
		u[d][i] = Secret(a[i],u[d][i+1]);
	}
	u[d][m + 1] = a[m + 1];
	for (int i = m + 2; i <= r; i++) {
		u[d][i] = Secret(u[d][i-1],a[i]);
	}

	go(d + 1, l, m);
	go(d + 1, m + 1, r);
}

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

int go2(int d, int l, int r, int L, int R)
{
	if (r < L || R < l) return 0;
	int m = (l + r) / 2;
	if (R == m) return u[d][L];
	if (L == m + 1) return u[d][R];
	if (L <= m && m + 1 <= R) return Secret(u[d][L], u[d][R]);

	int p = go2(d + 1, l, m, L, R);
	int q = go2(d + 1, m + 1, r, L, R);
	return p + q;
}

int Query(int L, int R) {
	if (L == R) return a[L];
	return go2(0,0,n-1,L,R);
}
# Verdict Execution time Memory Grader output
1 Correct 188 ms 2500 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 196 ms 2500 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 171 ms 2540 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 592 ms 4476 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 618 ms 4684 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 581 ms 4684 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 629 ms 4684 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 639 ms 4684 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 652 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 617 ms 4684 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1