#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define N 100005
int n;
long long t[4*N],mi[4*N],h[N],w[N],qs[N],m,pos,mod=1e9+7,ans;
void cre(int x,int l,int r){
if(l==r){t[x]=l,mi[x]=h[l];return ;}
int mid=(l+r)/2;
cre(x*2,l,mid);
cre(x*2+1,mid+1,r);
if(mi[x*2]<mi[x*2+1])t[x]=t[x*2];
else t[x]=t[x*2+1];
mi[x]=min(mi[x*2],mi[x*2+1]);
}
void query(int x,int l,int r,int ll,int rr){
if(l>rr||ll>r||ll>rr)return ;
if(ll<=l&&r<=rr){
if(mi[x]<m)m=mi[x],pos=t[x];
return ;
}
int mid=(l+r)/2;
query(x*2,l,mid,ll,rr);
query(x*2+1,mid+1,r,ll,rr);
}
void sol(int l,int r){
if(l>r)return ;
m=1e18;
query(1,1,n,l,r);
long long p=h[pos]*(h[pos]+1)/2%mod;
ans=(ans+p*(w[pos]*(w[pos]+1)/2%mod))%mod;
ans=(ans+p*(w[pos]*(qs[pos-1]-qs[l-1])%mod))%mod;
ans=(ans+p*(w[pos]*(qs[r]-qs[pos])%mod))%mod;
sol(l,pos-1),sol(pos+1,r);
}
int main(){
int i;
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%lld",&h[i]);
for(i=1;i<=n;i++)scanf("%lld",&w[i]),qs[i]=w[i]+qs[i-1];
for(i=1;i<=n;i++)qs[i]%=mod;
cre(1,1,n);
sol(1,n);
printf("%lld",ans);
return 0;
}
Compilation message
fancyfence.cpp: In function 'int main()':
fancyfence.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
fancyfence.cpp:45:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | for(i=1;i<=n;i++)scanf("%lld",&h[i]);
| ~~~~~^~~~~~~~~~~~~~
fancyfence.cpp:46:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | for(i=1;i<=n;i++)scanf("%lld",&w[i]),qs[i]=w[i]+qs[i-1];
| ~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
436 KB |
Output is correct |
2 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
436 KB |
Output is correct |
2 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |