# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
967066 | blackslex | Fancy Fence (CEOI20_fancyfence) | C++17 | 34 ms | 5576 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int M = 1e9 + 7, INV = 5e8 + 4;
int n;
int main() {
scanf("%d", &n);
vector<int> h(n + 5), w(n + 5);
vector<ll> pref(n + 5);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
for (int i = 1; i <= n; i++) scanf("%d", &w[i]), pref[i] = pref[i - 1] + w[i], pref[i] %= M;
vector<int> l(n + 5), r(n + 5, n + 1), sec(n + 5);
stack<int> st;
for (int i = 1; i <= n; i++) {
while (!st.empty() && h[i] <= h[st.top()]) {
sec[st.top()] = max(sec[st.top()], h[i]);
st.pop();
}
if (!st.empty()) l[i] = st.top();
st.emplace(i);
}
while (!st.empty()) st.pop();
for (int i = n; i >= 1; i--) {
while (!st.empty() && h[i] < h[st.top()]) {
sec[st.top()] = max(sec[st.top()], h[i]);
st.pop();
}
if (!st.empty()) r[i] = st.top();
st.emplace(i);
}
for (int i = 1; i <= n; i++) l[i]++, r[i]--;
ll ans = 0;
for (int i = 1; i <= n; i++) {
ll cursz = pref[r[i]] - pref[l[i] - 1]; cursz %= M; cursz += M; cursz %= M;
ll pos = cursz * (cursz + 1) % M * INV % M;
ans += pos * sec[i] % M * (h[i] - sec[i]) % M; ans %= M;
ans += pos * (h[i] - sec[i]) % M * (h[i] - sec[i] + 1) % M * INV % M; ans %= M;
}
printf("%lld", ans);
}
컴파일 시 표준 에러 (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... |