#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int P = 1E9 + 7, D = (P + 1) / 2;
i64 norm(i64 x) {
if (x < 0)
x += P;
else if (x >= P)
x -= P;
return x;
}
i64 C(i64 x) {
x = norm(x);
return x * (x + 1) % P * D % P;
}
int main() {
// freopen("input1.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<i64> h(n + 1), w(n + 1);
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1; i <= n; i++) {
cin >> w[i];
w[i] += w[i - 1];
w[i] %= P;
}
vector<i64> s{0};
i64 sum = 0;
i64 ans = 0;
for (int i = 1; i <= n; i++) {
while (h[s.back()] > h[i]) {
i64 height = h[s.back()];
i64 r = w[s.back()];
s.pop_back();
i64 l = w[s.back()];
// cout << " what the hell " << l << " " << r << " : " << height << "\n";
sum = norm(sum - C(r - l) * C(height) % P);
sum = norm(sum + C(r - l) * C(h[i]) % P);
}
// cout << sum << "\n";
ans = norm(ans + sum * (w[i] - w[i - 1]) % P);
// cout << ans << " ";
ans = norm(ans + C(w[i] - w[i - 1]) * C(h[i]) % P);
// cout << ans << "\n";
sum = norm(sum + (w[i] - w[i - 1]) * C(h[i]) % P);
s.push_back(i);
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
596 KB |
Output is correct |
3 |
Correct |
20 ms |
1756 KB |
Output is correct |
4 |
Correct |
23 ms |
3028 KB |
Output is correct |
5 |
Correct |
36 ms |
3048 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
596 KB |
Output is correct |
4 |
Correct |
13 ms |
1752 KB |
Output is correct |
5 |
Correct |
23 ms |
3032 KB |
Output is correct |
6 |
Correct |
27 ms |
3028 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
13 ms |
1752 KB |
Output is correct |
10 |
Correct |
31 ms |
3020 KB |
Output is correct |
11 |
Correct |
22 ms |
2944 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |