Submission #1055807

#TimeUsernameProblemLanguageResultExecution timeMemory
1055807trandangquangSecret (JOI14_secret)C++14
0 / 100
278 ms4692 KiB
#include <bits/stdc++.h> #include "secret.h" #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define eb emplace_back #define all(a) (a).begin(), (a).end() using namespace std; int n, a[1005], cnt; vector <int> ops[4005]; //int Secret(int X, int Y) { // /// program's // ++cnt; // return X+Y; //} void build(int id=1, int l=0, int r=n-1) { if(l == r) { ops[id] = {a[l]}; return; } // cout<<l<<" "<<r<<'\n'; int mid = (l + r) >> 1; ops[id] = {a[mid]}; FORD(i, mid-1, l) ops[id].eb(Secret(ops[id].back(), a[i])); reverse(all(ops[id])); ops[id].eb(a[mid+1]); FOR(i, mid+2, r) ops[id].eb(Secret(ops[id].back(), a[i])); // if(l == 4 && r == 7) { // cout << mid << '\n'; // for(int i:ops[id]) cout << i << " "; // cout << '\n'; // } build(id<<1, l, mid); build(id<<1|1, mid+1, r); } void Init(int N, int A[]) { n = N; FOR(i, 0, N-1) { a[i] = A[i]; } build(); } int get(int L, int R, int id=1, int l=0, int r=n-1) { int mid = (l+r) >> 1; if(R==mid) return ops[id][L-l]; if(L==mid+1) return ops[id][R-l]; if(L<=mid && mid+1<=R) return Secret(ops[id][L-l], ops[id][R-l]); if(R<mid) return get(L, R, id<<1, l, mid); return get(L, R, id<<1|1, mid+1, r); } int Query(int L, int R) { return get(L, R); } //int main() { // int b[] = {1,4,7,2,5,8,3,6}; // Init(8, b); //// cout<<cnt<<'\n'; //// cout<<Query(5,7)<<'\n'; //}
#Verdict Execution timeMemoryGrader output
Fetching results...