# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
877507 | Ivkosqn | Secret (JOI14_secret) | C++14 | 383 ms | 11608 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 endl '\n'
using namespace std;
const int maxn = 1024;
int pref[maxn][maxn], suff[maxn][maxn];
int lf[maxn], rg[maxn], a[maxn];
vector<int> mids;
void divide(int l, int r){
if(l > r)
return;
if(l == r){
suff[l][l] = a[l];
lf[l] = l;
rg[l] = l;
mids.push_back(l);
return;
}
int mid = (l + r) / 2;
mids.push_back(mid);
divide(l, mid - 1);
divide(mid + 1, r);
lf[mid] = l, rg[mid] = r;
suff[mid][mid] = a[mid];
pref[mid][mid + 1] = a[mid + 1];
for(int i = mid - 1;i >= l;i--)
suff[mid][i] = Secret(suff[mid][i + 1], a[i]);
for(int i = mid + 2;i <= r;i++)
pref[mid][i] = Secret(pref[mid][i - 1], a[i]);
}
void Init(int n, int A[]){
for(int i = 0;i < n;i++)
a[i] = A[i];
divide(0, n - 1);
}
int Query(int l, int r){
for(int x : mids){
if(lf[x] <= l && rg[x] >= r && x >= l && x <= r){
int ans = suff[x][l];
if(x != r)
ans = Secret(ans, pref[x][r]);
return ans;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |