Submission #954070

#TimeUsernameProblemLanguageResultExecution timeMemory
954070SharkyFancy Fence (CEOI20_fancyfence)C++17
30 / 100
20 ms3676 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9 + 7; int s(int x) { return (x * (x + 1) / 2) % mod; } int s(int l, int r) { return (s(r) - s(l-1)) % mod; } void norm(int& x) { x = (x % mod + mod) % mod; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; stack<pair<int, int>> st; int sum = 0, delta = 0; vector<int> 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]; for (int i = 1; i <= n; i++) { int h = H[i], w = W[i], aw = w; while (!st.empty() && st.top().first >= h) { auto [ff, ss] = st.top(); st.pop(); int nxth = h; if (!st.empty() && st.top().first >= h) nxth = st.top().first, st.top().second += ss; else aw += ss; delta -= (s(nxth + 1, ff) * ss) % mod; norm(delta); } // cout << delta << ' ' << h << ' ' << w << '\n'; st.push({h, w}); sum += delta * w + s(h) * s(w); norm(sum); delta += s(h) * w; norm(delta); // cout << sum << ' ' << delta << '\n'; } cout << sum << '\n'; }
#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...