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>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int inv = 500000004;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
int32_t main() {
int n;
cin >> n;
set<int> diff;
vector<int> h(n), w(n);
for(int &x : h) cin >> x, diff.insert(x);
for(int &x : w) cin >> x;
auto f = [&](ll a, ll b) {
ll p1 = 1ll * a * (a + 1) % mod * inv % mod;
ll p2 = 1ll * b * (b + 1) % mod * inv % mod;
return (p1 * p2) % mod;
};
if(diff.size() == 1) {
ll W = 0;
for(int &x : w) W += x, W %= mod;
cout << f(W, h[0]) << '\n';
return 0;
}
ll ans = 0;
for(int i=0; i<n; i++) {
ll W = w[i];
ll H = h[i];
for(int j=i+1; j<n; j++) {
W += w[j];
W %= mod;
H = min(H, 1ll * h[j]);
ll res = (f(W, H) - f(H, (W-w[i]+mod)%mod) + mod - f(H, (W-w[j]+mod)%mod) + mod + f(H, (W-w[i]-w[j]+2*mod)%mod)) % mod;
ans += res;
ans %= mod;
}
}
for(int i=0; i<n; i++) {
ans += f(h[i], w[i]);
ans %= mod;
}
cout << ans << '\n';
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... |