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 int long long
const int N = 1e5 + 10;
int r[N][3];
int w[N];
int h[N];
int mod = 1e9 + 7;
int power(int a,int b){
if (b==0)
return 1;
int ans = power(a,b/2);
ans = ans*ans;
ans %= mod;
if (b%2)
ans = ans*a;
return ans%mod;
}
int mod_inv(int k){
return power(k,mod-2);
}
int asd(int a){
int ans = (a*(a+1));
ans = ans%mod;
ans = ans*mod_inv(2);
ans = ans% mod;
return ans;
}
int answer(int W,int H){
int ans = asd(W);
int ans2 = asd(H);
return (ans*ans2)%mod ;
}
signed main(){
int n;
cin>>n;
for (int i=1;i<=n;i++)
cin>>h[i];
int ans = 0;
int W = 0;
for (int i=1;i<=n;i++){
cin>>w[i];
W += w[i];
W %= mod;
}
for (int i=1;i<=n;i++){
ans += answer(W,h[i]);
// cout<<i<<" "<<answer(W,h[i])<<endl;
ans = ans % mod;
ans -= answer(W,h[i-1]);
// cout<<answer(W,h[i-1])<<endl;
if (ans<0)
ans += mod;
W -= w[i];
if (W<0)
W += mod;
}
cout<<ans<<endl;
return 0;
}
# | 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... |