답안 #57088

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57088 2018-07-13T23:12:27 Z Benq 비밀 (JOI14_secret) C++14
100 / 100
678 ms 5668 KB
#include "secret.h"

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int* A;
int N;

struct node {
	node *c[2];
	vi v[2];

	void init(int L, int R) {
		if (L >= R) return;
		int M = (L+R)/2;
		v[0].pb(A[M]);
		for (int i = M-1; i >= L; --i) v[0].pb(Secret(A[i],v[0].back()));
		v[1].pb(A[M+1]);
		for (int i = M+2; i <= R; ++i) v[1].pb(Secret(v[1].back(),A[i]));

		c[0] = new node(); c[0]->init(L,M-1);
		c[1] = new node(); c[1]->init(M+2,R);
	}

	int query(int L, int R, int lo, int hi) {
		if (lo == hi) return A[lo];
		int M = (L+R)/2;
		if (hi < M) return c[0]->query(L,M-1,lo,hi);
		if (hi == M) return v[0][M-lo];
		if (lo > M+1) return c[1]->query(M+2,R,lo,hi);
		if (lo == M+1) return v[1][hi-M-1];
		return Secret(v[0][M-lo],v[1][hi-M-1]);
	}
};

node root;

void Init(int n, int a[]) {
	A = a; N = n;
	root.init(0,N-1);
}

int Query(int L, int R) {
	return root.query(0,N-1,L,R);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 2552 KB Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1
2 Correct 191 ms 2688 KB Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1
3 Correct 187 ms 2876 KB Output is correct - number of calls to Secret by Init = 3100, maximum number of calls to Secret by Query = 1
4 Correct 672 ms 5204 KB Output is correct - number of calls to Secret by Init = 6988, maximum number of calls to Secret by Query = 1
5 Correct 604 ms 5204 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
6 Correct 586 ms 5372 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
7 Correct 616 ms 5372 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
8 Correct 645 ms 5372 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
9 Correct 676 ms 5668 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
10 Correct 678 ms 5668 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1