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
#define pb push_back
#define sz(a) (int)a.size()
const int mxN = (int)1e5+10;
const int MOD = (int)1e9+7;
int Tw, Th;
int n, h[mxN], w[mxN];
vector<pair<int,int>> v;
int32_t main(){
cin >> n; int ans = 0;
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++){
int W = w[i]; Tw+=w[i], Th+=h[i];
while(i<n and h[i]==h[i+1]) W+=w[++i];
v.pb({h[i],W});
}
n = sz(v);
for(auto [h,w] : v){
if(h==1) continue;
ans+=w*(w+1); ans%=MOD;
}
cout << (ans+(Tw*Tw+Tw)/2)%MOD;
}
# | 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... |