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>
#define N 100002
#define M 1000000007ll
int n,h[N],w[N],l[N],r[N];
long long pw[N],z;
long long c2(long long x){return (x-1)*x%M*500000004ll%M;}
long long c(long long ww,long long hh)
{
ww%=M;
hh%=M;
return c2(ww+1)*c2(hh+1)%M;
}
void dfs(int u,int ll,int rr,int yy)
{
if(!u||ll>rr)return;
int y=h[u];
long long ww=(pw[rr]-pw[ll-1])%M;
z = (z + (c(ww,y) + M - c(ww,yy)) % M) % M;
dfs(l[u],ll,u-1,y);
dfs(r[u],u+1,rr,y);
}
int stk[N], top;
signed main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",h+i);
for(int i=1;i<=n;++i)scanf("%d",w+i),pw[i]=pw[i-1]+w[i];
for(int i=1;i<=n;++i)
{
int k=top;
while(k&&h[stk[k]]>h[i])--k;
if(k)r[stk[k]]=i;
if(k<top)l[i]=stk[k+1];
stk[++k]=i;
top=k;
}
dfs(stk[1],1,n,0);
printf("%lld",z);
}
Compilation message (stderr)
fancyfence.c: In function 'main':
fancyfence.c:32:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | scanf("%d",&n);
| ^~~~~~~~~~~~~~
fancyfence.c:33:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | for(int i=1;i<=n;++i)scanf("%d",h+i);
| ^~~~~~~~~~~~~~~
fancyfence.c:34:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | for(int i=1;i<=n;++i)scanf("%d",w+i),pw[i]=pw[i-1]+w[i];
| ^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |