# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
981958 | duckindog | Fancy Fence (CEOI20_fancyfence) | C++17 | 21 ms | 4444 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 100'000 + 10,
M = 1'000'000'007;
int n;
int h[N], w[N];
int d[N];
int fl[N], fr[N];
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> h[i];
for (int i = 1; i <= n; ++i) cin >> w[i];
for (int i = 1; i <= n; ++i) d[i] = (d[i - 1] + w[i]) % M;
{
stack<int> st; st.push(0);
for (int i = 1; i <= n; ++i) {
while (st.size() && h[st.top()] >= h[i]) st.pop();
fl[i] = st.top() + 1;
st.push(i);
}
}
{
stack<int> st; st.push(n + 1);
for (int i = n; i >= 1; --i) {
while (st.size() && h[st.top()] >= h[i]) st.pop();
fr[i] = st.top() - 1;
st.push(i);
}
}
auto cal = [&](int l, int r) { return 1ll * (l + r) * (r - l + 1) / 2 % M; };
auto add = [&](auto& x, long long val) { x = (x + val) % M; };
auto sub = [&](auto& x, long long val) { x = ((x - val) % M + M) % M; };
int answer = 0;
for (int i = 1; i <= n; ++i) {
if (fl[i] == fl[i - 1] && fr[i] == fr[i - 1] && h[i] == h[i - 1]) continue;
int l = fl[i], r = fr[i];
int height = max(h[l - 1], h[r + 1]);
add(answer, cal(1, d[r] - d[l - 1]) * cal(height + 1, h[i]));
}
cout << answer << "\n";
}
컴파일 시 표준 에러 (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... |