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 ll long long
const int mod = 1e9 + 7;
struct mint {
int v;
mint(ll x) {
if (x >= mod) {
v = x % mod;
} else {
v = x;
}
}
mint& operator+=(const mint &b) {
if ((v += b.v) >= mod) {
v -= mod;
}
return *this;
}
friend mint operator+(mint a, mint b) {
return a += b;
}
mint& operator*=(const mint &b) {
v = 1ll * v * b.v % mod;
return *this;
}
friend mint operator*(mint a, mint b) {
return a *= b;
}
mint power(mint a, int b) {
mint ans = 1;
while (b) {
if (b & 1) {
ans *= a;
}
a *= a, b >>= 1;
}
return ans;
}
mint& operator/=(const mint &b) {
v = 1ll * v * power(b, mod - 2).v % mod;
return *this;
}
friend mint operator/(mint a, mint b) {
return a /= b;
}
friend ostream& operator<<(ostream &os, mint a) {
return os << a.v;
}
friend istream& operator>>(istream &is, mint &a) {
return is >> a.v;
}
};
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
int h[n], w[n];
for (int i = 0; i < n; i++) {
cin >> h[i];
}
for (int i = 0; i < n; i++) {
cin >> w[i];
}
mint ans = 0;
for (int l = 0; l < n; l++) {
int mn = h[l];
ans += (mint(w[l]) * (w[l] + 1) / 2) * (mint(h[l]) * (h[l] + 1) / 2);
for (int r = l + 1; r < n; r++) {
mn = min(mn, h[r]);
ans += mint(w[l]) * w[r] * (mint(mn) * (mn + 1) / 2);
}
}
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... |