답안 #369505

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
369505 2021-02-21T18:57:05 Z kostia244 비밀 (JOI14_secret) C++17
100 / 100
597 ms 10816 KB
#include "secret.h"

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1<<17;
vector<int> L[maxn];
vector<int> R[maxn];
int n, a[maxn];
int oops(int x, int y) {
	//cout << x << " + " << y << endl;
	return Secret(x, y);
}
#define Secret oops
void solve(int l, int r) {
	if(l >= r) return;
	int mid = (l+r)/2;
	L[mid] = {a[mid]}, R[mid] = {};
	//cout << l << " | " << r << endl;
	for(int i = mid+1; i < r; i++) {
		if(R[mid].empty()) R[mid].push_back(a[i]);
		else R[mid].push_back(Secret(R[mid].back(), a[i]));
		//cout << "[" << mid+1 << ";" << i << "] = " << R[mid].back() << endl;
	}
	for(int i = mid; i-->l;) {
		if(!L[mid].empty()) L[mid].push_back(Secret(a[i], L[mid].back()));
		else L[mid].push_back(a[i]);
		//cout << "[" << i << ";" << mid << "] = " << L[mid].back() << endl;
	}
	solve(l, mid);
	solve(mid+1, r);
}
int query(int l, int r, int ql, int qr) {
	if(l >= r || qr <= l || r <= ql) return 0;
	int mid = (l+r)/2;
	if(ql <= mid && mid < qr) {
		//cout << ql << " " << qr << " " << mid << endl;
		qr = qr-mid-1;
		ql = mid-ql+1;
		//cout << ql << " " << qr << " " << mid << endl;
		if(ql == 0) return R[mid][qr-1];
		if(qr == 0) return L[mid][ql-1];
		return Secret(L[mid][ql-1], R[mid][qr-1]);
	}
	return query(l, mid, ql, qr)^query(mid+1, r, ql, qr);
}
void Init(int N, int A[]) {
	n = N;
	//for(int i = 0; i < n; i++) cout << A[i] << " "; cout << endl;
	for(int i = 0; i < n; i++) a[i] = A[i];
	solve(0, N);
}

int Query(int L, int R) {
	return query(0, n, L, R+1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 8684 KB Output is correct - number of calls to Secret by Init = 3331, maximum number of calls to Secret by Query = 1
2 Correct 155 ms 8684 KB Output is correct - number of calls to Secret by Init = 3340, maximum number of calls to Secret by Query = 1
3 Correct 150 ms 8660 KB Output is correct - number of calls to Secret by Init = 3349, maximum number of calls to Secret by Query = 1
4 Correct 541 ms 10612 KB Output is correct - number of calls to Secret by Init = 7491, maximum number of calls to Secret by Query = 1
5 Correct 597 ms 10680 KB Output is correct - number of calls to Secret by Init = 7499, maximum number of calls to Secret by Query = 1
6 Correct 533 ms 10572 KB Output is correct - number of calls to Secret by Init = 7499, maximum number of calls to Secret by Query = 1
7 Correct 514 ms 10732 KB Output is correct - number of calls to Secret by Init = 7499, maximum number of calls to Secret by Query = 1
8 Correct 521 ms 10732 KB Output is correct - number of calls to Secret by Init = 7499, maximum number of calls to Secret by Query = 1
9 Correct 538 ms 10604 KB Output is correct - number of calls to Secret by Init = 7499, maximum number of calls to Secret by Query = 1
10 Correct 515 ms 10816 KB Output is correct - number of calls to Secret by Init = 7499, maximum number of calls to Secret by Query = 1