# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
489746 | lukameladze | Secret (JOI14_secret) | C++14 | 443 ms | 8220 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 f first
#define s second
#define pb push_back
using namespace std;
const int M = 1005;
int a[M],ans[M][M],n;
/*int Secret(int a, int b) {
return min(1000000000, a + 2*(b/2));
}*/
void solve(int le, int ri) {
if (le == ri) return ;
int mid = (le + ri) / 2;
// cout<<le<<" "<<ri<<endl;
for (int i = mid - 1; i >= le; i--) {
ans[i][mid] = Secret(a[i],ans[i + 1][mid]);
}
for (int i = mid + 2; i <= ri; i++) {
ans[mid + 1][i] = Secret(ans[mid + 1][i - 1], a[i]);
}
solve(le, mid);
solve(mid + 1, ri);
}
int getans(int le, int ri, int start, int end) {
int mid = (le + ri) / 2;
if (le <= start && ri >= end) {
if (end == mid) {
return ans[start][mid];
}
if (start == mid + 1) {
return ans[mid + 1][end];
}
if (mid >= start && mid <= end) {
return Secret(ans[start][mid], ans[mid + 1][end]);
}
if (mid >= end) {
return getans(le,mid,start,end);
} else return getans(mid + 1, ri, start,end);
}
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; i++) {
a[i] = A[i];
ans[i][i] = a[i];
}
solve(0,n - 1);
}
int Query(int L,int R) {
return getans(0,n-1,L,R);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |