#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
const ll MOD = 1000000007;
const ll inv2 = 500000004;
int N;
ll h[100005], w[100005], ans;
vector<pll> mono = {pll{0, 0}};
signed main()
{
cin >> N;
for (int i = 1; i <= N; i++)
cin >> h[i];
for (int i = 1; i <= N; i++)
cin >> w[i];
N++;
for (int i = 1; i <= N; i++)
{
while (h[i] < mono.back().F)
{
ans = (ans + (((((mono.back().S * (mono.back().S + 1) % MOD) * inv2 % MOD) * (mono[mono.size() - 1].F - mono[mono.size() - 2].F) % MOD) * (mono[mono.size() - 1].F + mono[mono.size() - 2].F + 1) % MOD) * inv2 % MOD)) % MOD;
if (mono.size() == 2)
w[i] = (mono.back().S + w[i]) % MOD;
else
mono[mono.size() - 2].S = (mono.back().S + mono[mono.size() - 2].S) % MOD;
mono.pop_back();
}
if (h[i] == mono.back().F)
mono.back().S = (mono.back().S + w[i]) % MOD;
else
mono.emplace_back(pll{h[i], w[i]});
//for (pll i : mono)
// cout << "(" << i.F << ", " << i.S << ") ";
//cout << " | " << ans << '\n';
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
10 ms |
440 KB |
Output is correct |
3 |
Correct |
42 ms |
1020 KB |
Output is correct |
4 |
Correct |
88 ms |
1808 KB |
Output is correct |
5 |
Correct |
75 ms |
1996 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
8 ms |
432 KB |
Output is correct |
4 |
Correct |
39 ms |
964 KB |
Output is correct |
5 |
Correct |
85 ms |
1836 KB |
Output is correct |
6 |
Correct |
81 ms |
1808 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
8 ms |
844 KB |
Output is correct |
9 |
Correct |
39 ms |
1688 KB |
Output is correct |
10 |
Correct |
73 ms |
3916 KB |
Output is correct |
11 |
Correct |
75 ms |
3964 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |