Submission #1135862

#TimeUsernameProblemLanguageResultExecution timeMemory
1135862huutuanSecret (JOI14_secret)C++20
30 / 100
396 ms4424 KiB
#include "secret.h"

#include <bits/stdc++.h>

using namespace std;

int fake_secret(int x, int y){
	if (x==-1) return y;
	if (y==-1) return x;
	return Secret(x, y);
}

struct SegmentTree{
	int n;
	vector<int> t;
	void init(int _n){
		n=_n;
		t.assign(4*n+1, -1);
	}
	void build(int k, int l, int r, int a[]){
		if (l==r){
			t[k]=a[l];
			return;
		}
		int mid=(l+r)>>1;
		build(k<<1, l, mid, a);
		build(k<<1|1, mid+1, r, a);
		t[k]=fake_secret(t[k<<1], t[k<<1|1]);
	}
	int get(int k, int l, int r, int L, int R){
		if (r<L || R<l) return t[0];
		if (L<=l && r<=R) return t[k];
		int mid=(l+r)>>1;
		return fake_secret(get(k<<1, l, mid, L, R), get(k<<1|1, mid+1, r, L, R));
	}
} st;

void Init(int N, int A[]) {
	st.init(N);
	st.build(1, 0, N-1, A);
}

int Query(int L, int R) {
	return st.get(1, 0, st.n-1, L, R);
}
#Verdict Execution timeMemoryGrader output
Fetching results...