Submission #981958

#TimeUsernameProblemLanguageResultExecution timeMemory
981958duckindogFancy Fence (CEOI20_fancyfence)C++17
30 / 100
21 ms4444 KiB
#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"; }

Compilation message (stderr)

fancyfence.cpp: In function 'int32_t main()':
fancyfence.cpp:41:8: warning: variable 'sub' set but not used [-Wunused-but-set-variable]
   41 |   auto sub = [&](auto& x, long long val) { x = ((x - val) % M + M) % M; };
      |        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...