# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
935566 | Baizho | Secret (JOI14_secret) | C++14 | 395 ms | 8380 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>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
// #pragma GCC optimize("Ofast,unroll-loops,fast-math")
// #pragma GCC target("popcnt")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define pb push_back
const int mod = ll(1e9)+7;
const ll MOD = 998244353;
const long long inf = 5e18;
const int M = 1005;
int Secret(int x, int y);
int val[M][M], n, a[M];
void solve(int l, int r) {
if(l > r) return;
if(l == r) {
val[l][r] = a[l];
return;
}
int mid = (l + r) / 2;
val[mid][mid] = a[mid];
val[mid + 1][mid + 1] = a[mid + 1];
for(int i = mid - 1; i >= l; i --) val[i][mid] = Secret(val[i + 1][mid], a[i]);
for(int i = mid + 2; i <= r; i ++) val[mid + 1][i] = Secret(val[mid + 1][i - 1], a[i]);
solve(l, mid); solve(mid + 1, r);
}
void Init(int N, int A[]) {
n = N;
for(int i = 0; i < N; i ++) a[i] = A[i];
solve(0, n - 1);
}
int Query(int L, int R) {
int l = L, r = R, tl = 0, tr = n - 1;
if(l == r) return a[l];
while(tl <= tr) {
int mid = (tl + tr) / 2;
if(l <= mid && mid + 1 <= r) return Secret(val[l][mid], val[mid + 1][r]);
else if(r <= mid) tr = mid;
else tl = mid + 1;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |