#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
ll n, h[100005], w[100005];
stack<pll> stk;
ll mod = 1e9+7;
ll cans = 0, csum = 0;
void upd(ll&x){
if(x<0) x += mod;
if(x >= mod) x-=mod;
}
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n;
for(int i=0;i<n;i++) cin >> h[i];
for(int i=0;i<n;i++) cin >> w[i];
for(int i=0;i<n;i++) {
cans += (((h[i]+1)*h[i]/2)%mod)*(((w[i]+1)*w[i]/2)%mod);
ll cw = w[i];
while(!stk.empty() && stk.top().first > h[i]) {
cw += stk.top().second;
csum -= ((1ll*stk.top().first*stk.top().second) % mod);
upd(csum);
stk.pop();
}
cans += w[i]*csum%mod; upd(cans);
stk.emplace(h[i], cw);
csum += cw*h[i]%mod; upd(csum);
//cout << cans;
}
cout << cans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 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 |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
352 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 |
0 ms |
212 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 |
212 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 |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |