제출 #57088

#제출 시각아이디문제언어결과실행 시간메모리
57088Benq비밀 (JOI14_secret)C++14
100 / 100
678 ms5668 KiB
#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); }
#Verdict Execution timeMemoryGrader output
Fetching results...