#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long INF = 1ll << 60;
const int N = 1e5 + 5;
const int M = 1e9 + 7;
int pw(int a) {
a %= M;
return a * (a - 1) / 2 % M;
}
int H[N], W[N], n, ps[N], lt[N], rt[N];
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
FOR(i, 1, n + 1) cin >> H[i];
FOR(i, 1, n + 1) cin >> W[i];
vector<int> st{0};
H[0] = H[n + 1] = -INF;
FOR(i, 1, n + 1) {
while (H[i] < H[st.back()]) st.pop_back();
lt[i] = st.back();
st.push_back(i);
}
st = {n + 1};
for (int i = n; i >= 1; i--) {
while (H[i] <= H[st.back()]) st.pop_back();
rt[i] = st.back();
st.push_back(i);
}
FOR(i, 1, n + 1) ps[i] = ps[i - 1] + W[i];
int ans = 0;
FOR(i, 1, n + 1) {
int L = ps[i - 1] - ps[lt[i]] + 1;
int R = ps[rt[i] - 1] - ps[i] + 1;
int re = pw(L + R + W[i] - 1) - pw(L) - pw(R);
ans += re % M * pw(H[i] + 1) % M;
}
ans %= M;
if (ans < 0) ans += M;
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
8 ms |
3172 KB |
Output is correct |
4 |
Correct |
16 ms |
6124 KB |
Output is correct |
5 |
Correct |
17 ms |
5836 KB |
Output is correct |
6 |
Correct |
15 ms |
5588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
1108 KB |
Output is correct |
3 |
Correct |
10 ms |
3796 KB |
Output is correct |
4 |
Correct |
19 ms |
7020 KB |
Output is correct |
5 |
Correct |
19 ms |
7196 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
1100 KB |
Output is correct |
4 |
Correct |
10 ms |
3800 KB |
Output is correct |
5 |
Correct |
19 ms |
7004 KB |
Output is correct |
6 |
Correct |
19 ms |
7164 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
1108 KB |
Output is correct |
9 |
Correct |
10 ms |
3796 KB |
Output is correct |
10 |
Correct |
18 ms |
6856 KB |
Output is correct |
11 |
Correct |
19 ms |
7044 KB |
Output is correct |
12 |
Correct |
0 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
8 ms |
3160 KB |
Output is correct |
12 |
Correct |
16 ms |
6224 KB |
Output is correct |
13 |
Correct |
16 ms |
5748 KB |
Output is correct |
14 |
Correct |
15 ms |
5492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
3 ms |
1108 KB |
Output is correct |
17 |
Correct |
10 ms |
3796 KB |
Output is correct |
18 |
Correct |
20 ms |
6972 KB |
Output is correct |
19 |
Correct |
19 ms |
7112 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
1108 KB |
Output is correct |
22 |
Correct |
10 ms |
3800 KB |
Output is correct |
23 |
Correct |
18 ms |
6980 KB |
Output is correct |
24 |
Correct |
19 ms |
6972 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
848 KB |
Output is correct |
31 |
Correct |
3 ms |
852 KB |
Output is correct |
32 |
Correct |
10 ms |
3196 KB |
Output is correct |
33 |
Correct |
10 ms |
3256 KB |
Output is correct |
34 |
Correct |
19 ms |
5912 KB |
Output is correct |
35 |
Correct |
20 ms |
5968 KB |
Output is correct |
36 |
Correct |
20 ms |
6100 KB |
Output is correct |
37 |
Correct |
20 ms |
6092 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
18 ms |
6096 KB |
Output is correct |
40 |
Correct |
18 ms |
6136 KB |
Output is correct |
41 |
Correct |
18 ms |
6364 KB |
Output is correct |
42 |
Correct |
18 ms |
6672 KB |
Output is correct |