#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 2e5+5;
const int M = 26;
const ll inf = 1e15;
const ll mod = 1e9+7;
const ld ex = 1e-9;
int n, t, k, m, d[N], lab[N];
ll ans, tong, a[N], b[N], c[N], l[N], r[N], cnt;
string s;
struct node
{
int x, y, val;
int vx, vy;
node(){}
node(int _x, int _vx, int _y, int _vy)
{
x = _x;
vx = _vx;
y = _y;
vy = _vy;
}
};
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n&1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
ll C(ll u, ll v)
{
if(u > v)return 0;
return a[v] * b[u] % mod * b[v-u] % mod;
}
void add(ll& x, ll y)
{
x += y;
if(x >= mod)x -= mod;
}
vector<int> vi;
void sol()
{
cin >> n;
for(int i = 1; i <= n; i ++)cin >> a[i];
for(int i = 1; i <= n; i ++)
{
cin >> b[i];
c[i] = b[i];
b[i] += b[i-1];
}
for(int i = 1; i <= n; i ++)
{
while(!vi.empty() && a[vi.back()] > a[i])vi.pop_back();
l[i] = vi.empty() ? 0 : vi.back();
vi.pb(i);
}
vi.clear();
for(int i = n; i > 0; i --)
{
while(!vi.empty() && a[vi.back()] >= a[i])vi.pop_back();
r[i] = vi.empty() ? n+1 : vi.back();
vi.pb(i);
}
for(int i = 1; i <= n; i ++)
{
tong = ((b[r[i]-1]-b[i])*(b[i]-b[l[i]])%mod+c[i]*(c[i]+1)/2%mod+c[i]*(b[i-1]-b[l[i]])%mod) % mod;
cnt = a[i] * (a[i]+1) / 2 % mod;
//cout << cnt <<" ";
ans = (ans + cnt * tong % mod) % mod;
//cout << cnt <<" "<<tong << '\n';
}
cout << ans;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
*/
Compilation message
fancyfence.cpp: In function 'int main()':
fancyfence.cpp:94:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
94 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:95:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |