Submission #1267644

#TimeUsernameProblemLanguageResultExecution timeMemory
1267644trvhungSecret (JOI14_secret)C++20
100 / 100
343 ms8312 KiB
#include "secret.h" #include <bits/stdc++.h> // #include <ext/rope> // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; // using namespace __gnu_cxx; using namespace std; // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ll long long #define ull unsigned long long #define ld long double #define pb push_back #define bit(mask, i) ((mask >> i) & 1) #define el '\n' #define F first #define S second template <class X, class Y> bool maximize(X &x, const Y &y) { return (x < y ? x = y, 1 : 0); } template <class X, class Y> bool minimize(X &x, const Y &y) { return (x > y ? x = y, 1 : 0); } const int INF = 1e9; const ll LINF = 1e18; const int MOD = 1e9 + 7; const int MULTI = 0; const ld eps = 1e-9; const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; // R D L U const int ddx[4] = {-1, 1, 1, -1}, ddy[4] = {1, 1, -1, -1}; // UR DR DL UL const char cx[4] = {'R', 'D', 'L', 'U'}; const ll base = 31; const int nMOD = 2; const ll mods[] = {(ll)1e9 + 10777, (ll)1e9 + 19777, (ll)1e9 + 3, (ll)1e9 + 3777}; const int N = 1e3 + 5; int n, prep[N][N]; void dnc(int l, int r, int a[]) { int mid = (l + r) >> 1; prep[mid][mid] = a[mid]; prep[mid + 1][mid + 1] = a[mid + 1]; for (int i = mid + 2; i <= r; ++i) prep[mid + 1][i] = Secret(prep[mid + 1][i - 1], a[i]); for (int i = mid - 1; i >= l; --i) prep[mid][i] = Secret(a[i], prep[mid][i + 1]); if (l < mid) dnc(l, mid, a); if (mid + 1 < r) dnc(mid + 1, r, a); } void Init(int N, int A[]) { n = N; dnc(0, n - 1, A); } int Query(int L, int R) { int a = 0, b = n - 1; while (a != b) { int mid = (a + b) >> 1; if (mid >= L && mid < R) return Secret(prep[mid][L], prep[mid + 1][R]); else if (mid == R) return prep[mid][L]; else if (mid < L) a = mid + 1; else b = mid; } return prep[a][a]; }
#Verdict Execution timeMemoryGrader output
Fetching results...