#include <cmath>
#include <cassert>
#include <iostream>
#include <set>
#include <climits>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <type_traits>
#include <string>
#include <queue>
#include <map>
#include <stack>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimization ("Ofast")
using namespace std;
const int MOD = 1e9 + 7;
int64_t mult (int64_t x, int64_t y) {
return (x * y) % MOD;
}
int64_t c2 (int64_t x) {
return (x * (x + 1)/2) % MOD;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vector<int64_t> h(N), w(N);
vector<pair<int64_t, int64_t>> grid(N);
set<int> s;
for (int i = 0; i < N; i++) {
cin >> h[i];
s.insert(h[i]);
}
vector<int64_t> pref = {0};
for (int i = 0; i < N; i++) {
cin >> w[i];
pref.push_back(pref.back() + w[i]);
}
for (int i = 0; i < N; i++) {
grid[i] = make_pair(w[i], h[i]);
}
int64_t ans = 0;
for (int x: s) {
for (int i = 0; i < N; i++) {
if (h[i] == x) {
int l = i;
while (l >= 1) {
if (h[l - 1] >= x) {
l--;
} else {
break;
}
}
int r = i;
while (r < N - 1) {
if (h[r + 1] > x) {
r++;
} else {
break;
}
}
ans += (pref[x] - pref[l]) * (pref[r + 1] - pref[x]);
ans %= MOD;
}
}
}
for (int i = 0; i < N; i++) {
ans += mult(c2(grid[i].first), c2(grid[i].second));
ans %= MOD;
}
cout << ans;
return 0;
for (int i = 0; i < N; i++) {
ans += mult(c2(grid[i].first), c2(grid[i].second));
ans %= MOD;
int64_t min_w = grid[i].second;
for (int j = i + 1; j < N; j++) {
min_w = min(min_w, grid[j].second);
ans += mult(c2(min_w), mult(grid[i].first, grid[j].first));
ans %= MOD;
}
}
cout << ans << '\n';
}
Compilation message
fancyfence.cpp:16: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
16 | #pragma GCC optimization ("O3")
|
fancyfence.cpp:17: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
17 | #pragma GCC optimization ("unroll-loops")
|
fancyfence.cpp:18: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
18 | #pragma GCC optimization ("Ofast")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
588 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |