Submission #577526

#TimeUsernameProblemLanguageResultExecution timeMemory
577526tengiz05Fancy Fence (CEOI20_fancyfence)C++17
100 / 100
34 ms5080 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; constexpr int P = 1E9 + 7, D = (P + 1) / 2; i64 norm(i64 x) { if (x < 0) x += P; else if (x >= P) x -= P; return x; } i64 C(i64 x) { x = norm(x); return x * (x + 1) % P * D % P; } int main() { // freopen("input1.txt", "r", stdin); ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<i64> 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]; w[i] += w[i - 1]; w[i] %= P; } vector<i64> s{0}; i64 sum = 0; i64 ans = 0; for (int i = 1; i <= n; i++) { while (h[s.back()] > h[i]) { i64 height = h[s.back()]; i64 r = w[s.back()]; s.pop_back(); i64 l = w[s.back()]; // cout << " what the hell " << l << " " << r << " : " << height << "\n"; sum = norm(sum - (r - l) * C(height) % P); sum = norm(sum + (r - l) * C(h[i]) % P); } // cout << sum << "\n"; ans = norm(ans + sum * (w[i] - w[i - 1]) % P); // cout << ans << " "; ans = norm(ans + C(w[i] - w[i - 1]) * C(h[i]) % P); // cout << ans << "\n"; sum = norm(sum + (w[i] - w[i - 1]) * C(h[i]) % P); s.push_back(i); } 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...