#include<bits/stdc++.h>
using namespace std;
using lli = long long;
const int mod = 1e9 + 7;
const int maxn = 1e6;
lli s[maxn], h[maxn], w[maxn], b[maxn], c[maxn];
vector <lli> v;
int main()
{
lli n;
cin >> n;
for (lli i = 1; i <= n; i ++)
{
cin >> h[i];
}
for (lli i = 1; i <= n; i ++)
{
cin >> w[i];
}
for (lli i = 1; i <= n; i ++)
{
s[i] = s[i - 1] + w[i];
}
lli k = 0;
for (lli i = 1; i <= n; i ++)
{
while (!v.empty() && h[v.back()] > h[i])
{
v.pop_back();
}
if (v.empty())
{
k ++;
b[k] = 0;
} else
{
k ++;
b[k] = s[v.back()];
}
v.push_back(i);
}
while (!v.empty())
{
v.pop_back();
}
k = 0;
for (lli i = n; i >= 1; i --)
{
while (!v.empty() && h[v.back()] >= h[i])
{
v.pop_back();
}
if (v.empty())
{
k ++;
c[k] = s[n] + 1;
} else
{
k ++;
c[k] = s[v.back()];
}
v.push_back(i);
}
lli res = 0, j = n;
for (lli i = 1; i <= n; i ++)
{
lli p = (h[i] + 1) * h[i] / 2;
lli q = (w[i] + 1) * w[i] / 2;
lli r = c[j] - b[i] - w[i];
res += (p * q * r);
res %= mod;
//cout << res << " " << c[j] << " " << b[i] << " " << r << endl;
j --;
}
cout << res % mod;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
2 ms |
6492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6600 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
2 ms |
6596 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
2 ms |
6492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |