#include <bits/stdc++.h>
using namespace std;
#define int long long
#define moddy 1000000007
int findRect(int height, int width, int inc)
{
//cout << height << " " << width << " " << inc << "\n";
int ans = (height + 1) * height / 2;
ans *= width;
ans *= inc;
return ans;
}
int incRect(int height, int width)
{
//cout << height << " " << width << "\n";
int ans = height * (height + 1)/2;
ans *= ((width + 1) * width/2);
return ans;
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int N;
cin >> N;
vector<int>heights(N + 1);
vector<int>widths(N + 1);
for (int a = 1; a <= N; a++)
{
cin >> heights[a];
}
for (int a = 1; a <= N; a++)
{
cin >> widths[a];
}
int ans = 0;
vector<vector<pair<int,int>>>rects(N + 1); //height, width
for (int curr = 1; curr <= N; curr++)
{
//cout << "at rectangle " << curr << ":\n";
int at = 0;
for (auto prev: rects[curr - 1])
{
if (at == heights[curr])
{
break;
}
ans += (findRect(min(heights[curr], prev.first) - at, prev.second, widths[curr]));
ans %= moddy;
rects[curr].push_back({min(heights[curr], prev.first), prev.second + widths[curr]});
at = min(heights[curr], prev.first);
//cout << "\n";
}
ans += incRect(heights[curr],widths[curr]);
ans %= moddy;
if (at != heights[curr])
{
rects[curr].push_back({heights[curr],widths[curr]});
}
}
ans %= moddy;
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
360 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |