# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
558643 | groshi | Secret (JOI14_secret) | C++17 | 0 ms | 0 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<iostream>
#include "secret.h"
using namespace std;
int n;
int t[100000];
long long wyn[1010][1010];
/*long long Secret(int x,int y)
{
return x+y;
}*/
void rob(int l,int r)
{
if(l>r)
return;
int sre=(l+r)/2;
wyn[sre][sre]=t[sre];
wyn[sre+1][sre+1]=t[sre+1];
for(int i=sre+2;i<=r;i++)
wyn[sre+1][i]=Secret(wyn[sre+1][i-1],t[i]);
for(int i=sre-1;i>=l;i--)
wyn[i][sre]=Secret(wyn[i+1][sre],t[i]);
if(sre>l)
rob(l,sre);
if(sre+1<r)
rob(sre+1,r);
}
long long zap(int x1,int y1,int l,int r)
{
int mid=(x1+y1)/2;
if(x1==y1)
return wyn[x1][y1];
if(l<=mid && mid<r)
return Secret(wyn[l][mid],wyn[mid+1][r]);
if(l>mid)
return zap(mid+1,r,l,r);
else return zap(l,mid,l,r);
}
void Init(int N,int A[])
{
n=N;
for(int i=0;i<n;i++)
t[i]=A[i];
rob(0,n-1);
}
long long Query(int l,int r)
{
return zap(0,n-1,l,r);
}