#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++)
{
if (mono.empty())
mono.emplace_back(pll{h[i], w[i]});
else
{
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;
pll p = mono.back();
mono.pop_back();
mono.back().S = (mono.back().S + p.S) % MOD;
}
if (h[i] == mono.back().F)
mono.back().S = (mono.back().S + w[i]) % MOD;
else
mono.emplace_back(pll{h[i], w[i]});
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
8 ms |
588 KB |
Output is correct |
3 |
Correct |
39 ms |
1992 KB |
Output is correct |
4 |
Correct |
72 ms |
3764 KB |
Output is correct |
5 |
Correct |
76 ms |
3816 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
8 ms |
552 KB |
Output is correct |
4 |
Correct |
39 ms |
1980 KB |
Output is correct |
5 |
Correct |
76 ms |
3748 KB |
Output is correct |
6 |
Correct |
82 ms |
3788 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
9 ms |
1012 KB |
Output is correct |
9 |
Correct |
44 ms |
2624 KB |
Output is correct |
10 |
Correct |
80 ms |
5780 KB |
Output is correct |
11 |
Correct |
80 ms |
5848 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |