# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
13702 | eaststar | 케이크 (JOI13_cake) | C++98 | 159 ms | 23004 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 <stdio.h>
#include <algorithm>
using namespace std;
int a[300010],t[300010][2],st[300010],p;
long long b[2][300010],ans[300010];
void trav(int n,int s,int e){
int i=s,j=e,l=t[n][0],r=t[n][1];
long long sum=a[n];
if(s==e)ans[n]+=sum,ans[n+1]-=sum;
if(s>=e)return;
while(l||r){
if(a[l]<a[r])sum+=b[j%2][l]-b[j%2][i-1],i=l+1,l=t[l][1];
else sum+=b[i%2][j]-b[i%2][r-1],j=r-1,r=t[r][0];
}
ans[n]+=sum,ans[n+1]-=sum;
sum=b[s%2][e]-b[s%2][n-1];
ans[s]+=sum,ans[n]-=sum;
sum=b[e%2][n]-b[e%2][s-1];
ans[n+1]+=sum,ans[e+1]-=sum;
if(t[n][0])trav(t[n][0],s,n-1);
if(t[n][1])trav(t[n][1],n+1,e);
}
int main(){
int i,n,mn=2e9,mi,l=1,r,chk=0;
long long s=0;
scanf("%d",&n);
for(i=1;i<=n;++i){
scanf("%d",a+i);
if(mn>a[i])mn=a[i],mi=i;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |