#include <bits/stdc++.h>
#define int long long
using namespace std;
const int Mod = 1e9 + 7;
int n;
int h[100005],w[100005];
int sp[100005];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>h[i];
}
for(int i=1;i<=n;i++)
{
cin>>w[i];
sp[i] = (sp[i-1] + w[i]) % Mod;
}
stack<int> st,st_sum;
st.push(0);
long long sum = 0, rez = 0;
for(int i=1;i<=n;i++)
{
while(h[i]<=h[st.top()])
{
sum = (sum - st_sum.top() + Mod) % Mod;
st_sum.pop();
st.pop();
}
rez += 1LL * sum * w[i] % Mod;
rez %= Mod;
rez += w[i] * (w[i] + 1) / 2 % Mod * (h[i] * (h[i]+1) / 2 % Mod) % Mod;
int c_sum = (sp[i] - sp[st.top()] + Mod) % Mod * (h[i] * (h[i] + 1) / 2 % Mod) % Mod;
sum += c_sum;
sum %= Mod;
st_sum.push(c_sum);
st.push(i);
}
cout<<rez<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |