# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
656877 | Danilo21 | Secret (JOI14_secret) | C++17 | 472 ms | 12364 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "secret.h"
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) __builtin_popcountll(a)
#define bithigh(a) 63-__builtin_clzll(a)
#define lg bithigh
ll highpow(ll a) { return 1LL << (ll)lg(a); }
using namespace std;
const ll LINF = 4e18;
const int mxN = 1e3+10, INF = 2e9;
ll n, m, a[mxN], table[mxN][mxN];
void Build(int l, int r){
if (l == r) return;
int m = (l + r)>>1;
for (int i = m-1; i >= l; i--)
if (!~table[i][m])
table[i][m] = Secret(a[i], table[i+1][m]);
for (int i = m+2; i <= r; i++)
if (!~table[m+1][i])
table[m+1][i] = Secret(table[m+1][i-1], a[i]);
Build(l, m); Build(m+1, r);
}
void Init(int N, int A[]) {
memset(table, -1, sizeof(table));
n = N;
for (int i = 0; i < n; i++)
a[i] = table[i][i] = A[i];
Build(0, n-1);
}
int Query(int L, int R) {
if (~table[L][R]) return table[L][R];
for (int i = L; i < R; i++)
if (~table[L][i] && ~table[i+1][R])
return Secret(table[L][i], table[i+1][R]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |