Submission #376324

#TimeUsernameProblemLanguageResultExecution timeMemory
376324cheissmartSecret (JOI14_secret)C++14
100 / 100
524 ms4588 KiB
#include "secret.h"
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 1005;

int n, *a;
int t[N][11];

void build(int l = 0, int r = n, int depth = 0) {
	if(r - l == 1) return;
	int m = (l + r) / 2;
	t[m - 1][depth] = a[m - 1];
	for(int i = m - 2; i >= l; i--)
		t[i][depth] = Secret(a[i], t[i + 1][depth]);
	t[m][depth] = a[m];
	for(int i = m + 1; i < r; i++)
		t[i][depth] = Secret(t[i - 1][depth], a[i]);
	build(l, m, depth + 1);
	build(m, r, depth + 1);
}

void Init(int N, int A[]) {
	n = N, a = A;
	build(0, n);
}

int qry(int l, int r, int tl = 0, int tr = n, int depth = 0) {
	int tm = (tl + tr) / 2;
	if(l < tm && r >= tm) return Secret(t[l][depth], t[r][depth]);
	else if(r < tm) return qry(l, r, tl, tm, depth + 1);
	else return qry(l, r, tm, tr, depth + 1);
}

int Query(int l, int r) {
	if(l == r) return a[l];
	return qry(l, r);
}

#Verdict Execution timeMemoryGrader output
Fetching results...