# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
577522 | tengiz05 | Fancy Fence (CEOI20_fancyfence) | C++17 | 3 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int P = 1E9 + 7, D = (P + 1) / 2;
i64 norm(i64 x) {
if (x < 0)
x += P;
else if (x >= P)
x -= P;
return x;
}
i64 C(i64 x) {
x = norm(x);
return x * (x + 1) % P * D % P;
}
int main() {
freopen("input1.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<i64> h(n + 1), w(n + 1);
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1; i <= n; i++) {
cin >> w[i];
w[i] += w[i - 1];
w[i] %= P;
}
vector<i64> s{0};
i64 sum = 0;
i64 ans = 0;
for (int i = 1; i <= n; i++) {
while (h[s.back()] > h[i]) {
i64 height = h[s.back()];
i64 r = w[s.back()];
s.pop_back();
i64 l = w[s.back()];
// cout << " what the hell " << l << " " << r << " : " << height << "\n";
sum = norm(sum - C(r - l) * C(height) % P);
sum = norm(sum + C(r - l) * C(h[i]) % P);
}
// cout << sum << "\n";
ans = norm(ans + sum * (w[i] - w[i - 1]) % P);
// cout << ans << " ";
ans = norm(ans + C(w[i] - w[i - 1]) * C(h[i]) % P);
// cout << ans << "\n";
sum = norm(sum + (w[i] - w[i - 1]) * C(h[i]) % P);
s.push_back(i);
}
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |