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<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
#define int long long
const int MAX=1e5+3,mod=1e9+7;
int dp[MAX];
void maxx(int &a,int b){if(b>a) a=b;}
void minn(int &a,int b){if(b<a) a=b;}
void PL(int &a,int b){a+=b;if(a>=mod) a-=mod;}
int b[MAX];
int a[MAX];
int D[MAX];
int gs(int x){
return (x*(x+1)/2)%mod;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
int ans=0;
int top=0;
for(int i=1,x;i<=n;i++){
cin>>x;
b[i]=(b[i-1]+x)%mod;
while(a[i]<a[D[top]]) top--;
int u=D[top];
dp[i]=( gs(a[i])*(b[i]-b[u])+dp[u] )%mod;
(ans+=dp[u]*x+gs(a[i])*(gs(x)+x*(b[i-1]-b[u])%mod) )%=mod;
D[++top]=i;
}
PL(ans,mod);
cout<<ans;
}
# | 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... |