#include<stdio.h>
#define int long long
#define N 100002
#define M 1000000007ll
int n,h[N],w[N],p[N],l[N],r[N];
long long pw[N],z;
long long c(long long ww,long long hh)
{
ww%=M;
hh%=M;
return (((ww+1ll)*ww/2)%M*((hh+1ll)*hh/2)%M)%M;
}
void dfs(int u,int ll,int rr,int yy)
{
int y=h[u];
if(!u||ll>rr)return;
long long ww=(pw[rr]-pw[ll-1]);
z = (z + (c(ww,y) + M - c(ww,yy)) % M) % M;
//printf(" AT %lld : [%lld %lld], %lld %lld\n",u,pw[ll-1]+1,pw[rr],y,z);
dfs(l[u],ll,u-1,y);
dfs(r[u],u+1,rr,y);
}
int stk[N], top;
signed main()
{
scanf("%lld",&n);
for(int i=1;i<=n;++i)scanf("%lld",h+i);
for(int i=1;i<=n;++i)scanf("%lld",w+i),pw[i]=pw[i-1]+w[i];
//for(int i=1;i<=n;++i)printf(" %d %d %d\n",i,l[i],r[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
fancyfence.c: In function 'main':
fancyfence.c:31:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%lld",&n);
| ^~~~~~~~~~~~~~~~
fancyfence.c:32:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | for(int i=1;i<=n;++i)scanf("%lld",h+i);
| ^~~~~~~~~~~~~~~~~
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("%lld",w+i),pw[i]=pw[i-1]+w[i];
| ^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4528 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4524 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
14 ms |
5556 KB |
Output is correct |
4 |
Correct |
17 ms |
6488 KB |
Output is correct |
5 |
Correct |
16 ms |
5976 KB |
Output is correct |
6 |
Correct |
17 ms |
5884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4528 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |