#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<ll>
#define vp vector<pp>
#define vvi vector<vi>
#define vvp vector<vp>
#define pp pair<ll, ll>
#define inf 1000000000000000
#define rep(i,n) for(ll i = 0; i < n; i++)
#define mod 1000000007
ll get(ll h, ll w){
return (((h * (h + 1)/ 2) % mod) * ((w * (w + 1) / 2) % mod) % mod);
}
int main(){
ll n;
cin >> n;
vi H(n + 1), W(n + 1);
rep(i,n){
cin >> H[i];
}
H[n] = 0; W[n] = 0;
rep(i,n) cin >> W[i];
vector<pp> q;
q.push_back({-1, -1});
ll ans = 0;
rep(i,n + 1){
ll akt = 0;
while(q.back().first >= H[i]){
pp seclast = q[q.size() - 2];
if(seclast.first >= H[i]){
ans += get(q.back().first, q.back().second);
ans -= get(seclast.first, q.back().second);
ans %= mod;
ll www = q.back().second;
q.pop_back();
q.back().second += www;
}else{
ans += get(q.back().first, q.back().second);
ans -= get(H[i], q.back().second);
ans %= mod;
akt = q.back().second;
q.pop_back();
}
}
q.push_back({H[i], W[i] + akt});
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |