#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll nc2(ll x){
return x * (x - 1) / 2 % mod;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int nums; cin >> nums;
vector<ll> wv(nums), hv(nums);
for (int i = 0; i < nums; i++) cin >> hv[i];
for (int i = 0; i < nums; i++) cin >> wv[i];
vector<tuple<ll, ll, ll>> st;
ll ans = 0, sum = 0;
for (int i = 0; i < nums; i++){
ans = (ans + nc2(hv[i] + 1) * nc2(wv[i] + 1) % mod) % mod;
ll wk = 0;
while (!st.empty() && get<0>(st.back()) >= hv[i]){
ll h, w, val; tie(h, w, val) = st.back();
wk = (wk + w) % mod; sum = (sum - val + mod) % mod;
st.pop_back();
}
ans = (ans + wk * nc2(hv[i] + 1) % mod * wv[i] % mod) % mod;
ans = (ans + sum * wv[i] % mod) % mod;
wk = (wk + wv[i]) % mod;
ll nval = wk * nc2(hv[i] + 1) % mod;
sum = (sum + nval) % mod;
st.push_back({hv[i], wk, nval});
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
8 ms |
1116 KB |
Output is correct |
4 |
Correct |
14 ms |
1884 KB |
Output is correct |
5 |
Correct |
15 ms |
1880 KB |
Output is correct |
6 |
Correct |
14 ms |
1880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
10 ms |
1112 KB |
Output is correct |
4 |
Correct |
17 ms |
1884 KB |
Output is correct |
5 |
Correct |
18 ms |
2040 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
9 ms |
1252 KB |
Output is correct |
5 |
Correct |
18 ms |
2040 KB |
Output is correct |
6 |
Correct |
17 ms |
1880 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
1052 KB |
Output is correct |
9 |
Correct |
9 ms |
2136 KB |
Output is correct |
10 |
Correct |
18 ms |
5072 KB |
Output is correct |
11 |
Correct |
19 ms |
6352 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
388 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
8 ms |
1116 KB |
Output is correct |
12 |
Correct |
14 ms |
1884 KB |
Output is correct |
13 |
Correct |
14 ms |
1884 KB |
Output is correct |
14 |
Correct |
14 ms |
1884 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
9 ms |
1116 KB |
Output is correct |
18 |
Correct |
18 ms |
2040 KB |
Output is correct |
19 |
Correct |
17 ms |
1884 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
1048 KB |
Output is correct |
22 |
Correct |
9 ms |
2136 KB |
Output is correct |
23 |
Correct |
18 ms |
5072 KB |
Output is correct |
24 |
Correct |
18 ms |
5840 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
9 ms |
1116 KB |
Output is correct |
33 |
Correct |
9 ms |
1116 KB |
Output is correct |
34 |
Correct |
20 ms |
1884 KB |
Output is correct |
35 |
Correct |
17 ms |
2136 KB |
Output is correct |
36 |
Correct |
18 ms |
1884 KB |
Output is correct |
37 |
Correct |
18 ms |
2036 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
18 ms |
2044 KB |
Output is correct |
40 |
Correct |
18 ms |
1884 KB |
Output is correct |
41 |
Correct |
18 ms |
2392 KB |
Output is correct |
42 |
Correct |
19 ms |
3540 KB |
Output is correct |