Submission #656657

#TimeUsernameProblemLanguageResultExecution timeMemory
656657CDuongSecret (JOI14_secret)C++17
100 / 100
524 ms8352 KiB
/* #pragma GCC optimize("Ofast") #pragma GCC target("avx2") #pragma GCC optimize("unroll-loops") */ #include <bits/stdc++.h> #include "secret.h" #define taskname "bai3" #define all(x) x.begin(), x.end() #define ll long long #define ld long double #define pb push_back #define mp make_pair #define ff first #define ss second #define pii pair<int, int> using namespace std; const int mxN = 1e3 + 5; const int mod = 1e9 + 7; const ll oo = 1e18; int n, a[mxN], pref[4 * mxN][mxN]; void build(int l, int r, int idx, int dir) { if(l == r) { pref[idx][1] = a[l]; return; } if(l == r - 1) { if(dir) pref[idx][1] = a[l]; else pref[idx][1] = a[r]; pref[idx][2] = Secret(a[l], a[r]); return; } int mid = (l + r) >> 1; build(l, mid, idx * 2, 0); build(mid + 1, r, idx * 2 + 1, 1); if(l == 1 && r == n) return; if(dir) { pref[idx][1] = a[l]; for(int i = 2; i <= (r - l + 1); ++i) pref[idx][i] = Secret(pref[idx][i - 1], a[l + i - 1]); return; } pref[idx][1] = a[r]; for(int i = 2; i <= (r - l + 1); ++i) pref[idx][i] = Secret(a[r + 1 - i], pref[idx][i - 1]); } void Init(int N, int A[]) { n = N; for(int i = 1; i <= n; ++i) a[i] = A[i - 1]; build(1, n, 1, 0); } int query(int l, int r, int idx, int u, int v) { int mid = (l + r) >> 1; if(u <= mid && mid <= v) { if(v == mid) return pref[idx * 2][v - u + 1]; int tmp1 = pref[idx * 2][mid - u + 1]; int tmp2 = pref[idx * 2 + 1][v - mid]; int ans = Secret(tmp1, tmp2); return ans; } if(mid > v) return query(l, mid, idx * 2, u, v); return query(mid + 1, r, idx * 2 + 1, u, v); } int Query(int L, int R) { ++L; ++R; if(L == R) return a[L]; if(L == R - 1) return Secret(a[L], a[R]); return query(1, n, 1, L, R); }
#Verdict Execution timeMemoryGrader output
Fetching results...