#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, mod6 = 166666668ll;
ll cans = 0, csum = 0;
void upd(ll&x){
if(x<0) x += mod;
if(x >= mod) x-=mod;
}
ll func(ll x) {
return (x*(x+1)/2)%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)%mod; upd(cans);
ll cw = w[i];
while(!stk.empty() && stk.top().first > h[i]) {
cw += stk.top().second; upd(cw);
csum -= ((1ll*func(stk.top().first)*stk.top().second) % mod);
upd(csum);
stk.pop();
}
cans += cw*csum%mod; upd(cans);
stk.emplace(h[i], cw);
csum += cw*func(h[i])%mod; upd(csum);
//cout << cans << '\n';
}
cout << cans;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
616 KB |
Output is correct |
3 |
Correct |
15 ms |
1800 KB |
Output is correct |
4 |
Correct |
23 ms |
3440 KB |
Output is correct |
5 |
Correct |
22 ms |
3456 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
596 KB |
Output is correct |
4 |
Correct |
16 ms |
1916 KB |
Output is correct |
5 |
Correct |
32 ms |
3432 KB |
Output is correct |
6 |
Correct |
25 ms |
3440 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
11 ms |
1920 KB |
Output is correct |
10 |
Correct |
21 ms |
3484 KB |
Output is correct |
11 |
Correct |
26 ms |
3596 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |