Submission #544167

#TimeUsernameProblemLanguageResultExecution timeMemory
544167tengiz05Fancy Fence (CEOI20_fancyfence)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using i64 = long long; constexpr int P = 1E9 + 7; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::vector<i64> h(n + 1), w(n + 1); for (int i = 1; i <= n; i++) { std::cin >> h[i]; } for (int i = 1; i <= n; i++) { std::cin >> w[i]; w[i] += w[i - 1]; } std::vector<std::pair<i64, i64>> s; s.emplace_back(0, 0); i64 a = 0; i64 ans = 0; for (int i = 1; i <= n; i++) { while (s.back().first >= h[i]) { i64 x = s.back().second - s[int(s.size()) - 2].second; a -= s.back().first * (x * (x + 1) / 2); s.pop_back(); } if (s.back().second != w[i - 1]) { i64 x = w[i - 1] - s.back().second; a += h[i] * (x * (x + 1) / 2); s.emplace_back(h[i], w[i - 1]); } ans += a % P * (w[i] - w[i - 1]) % P; i64 x = w[i] - w[i - 1]; i64 y = h[i]; ans += (x * (x + 1) / 2 % P) * (y * (y + 1) / 2 % P) % P; a += h[i] * (w[i] - s.back().second); s.emplace_back(h[i], w[i]); } std::cout << ans << "\n"; return 0; }
#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...