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;
typedef long long ll;
const int N=1e5+5;
const ll mod=1e9+7;
const ll inv2=5e8+4;
int n;
ll h[N],w[N];
ll ans;
ll calc(ll x){
x%=mod;
return x*(x+1)%mod*inv2%mod;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n;
for(int i=1;i<=n;i++)cin >> h[i];
for(int i=1;i<=n;i++)cin >> w[i];
for(int i=1;i<=n;i++){
ll rmq=h[i];
ans+=calc(w[i])*calc(h[i])%mod;
ans%=mod;
for(int j=i-1;j>=1;j--){
rmq=min(rmq,h[j]);
ans+=calc(rmq)*w[i]%mod*w[j]%mod;
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... |