// CEOI.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
using namespace std;
#define ll long long
#include <vector>
#define vll vector<ll>
const int m = 1e9 + 7;
ll c(ll x) {
return ((x * (x - 1)) / 2) % m;
}
int main()
{
int n;
cin >> n;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vll resh(n + 2);
vll h(n+2);
for (int i = 0; i < n; i++) {
int hi;
cin >> hi;
h[i + 1] = hi;
}
for (int i = 0; i < n; i++) {
int w;
cin >> w;
resh[i + 1] = (resh[i] + w)%m;
}
vll v;
vll l(n+2);
vll r(n+2);
for (int i = 0; i < n+2; i++) {
while (!v.empty() && h[v.back()] > h[i]) {
r[v.back()] = i;
v.pop_back();
}
v.push_back(i);
}
for (int i = n+1; i >=0; i--) {
while (!v.empty() && h[v.back()] >= h[i]) {
l[v.back()] = i;
v.pop_back();
}
v.push_back(i);
}
ll ans=0;
for (int i = 1; i <= n; i++) {
ans = (ans + c(h[i]+1)*((resh[i] - resh[l[i]]) * (resh[r[i] - 1] - resh[i - 1]))%m) % m;
ans = (ans - c(resh[i] - resh[i - 1] ) * c(h[i] + 1)) % m;
}
if (ans < 0)
ans += m;
cout << ans;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
10 ms |
2260 KB |
Output is correct |
4 |
Correct |
18 ms |
4564 KB |
Output is correct |
5 |
Correct |
19 ms |
4056 KB |
Output is correct |
6 |
Correct |
17 ms |
3568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |