Submission #881361

#TimeUsernameProblemLanguageResultExecution timeMemory
881361nima_aryanFancy Fence (CEOI20_fancyfence)C++17
12 / 100
1 ms348 KiB
/** * author: NimaAryan * created: 2023-12-01 09:55:42 **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "algo/debug.h" #endif using i64 = long long; constexpr i64 M = 1E9 + 7; void add(i64& x, i64 y) { if ((x += y) >= M) { x -= M; } } i64 C(i64 h, i64 w) { return ((h * (h + 1) / 2) % M) * ((w * (w + 1) / 2) % M) % M; } i64 F(i64 h) { return (h * (h + 1) / 2) % M; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<i64> h(N); for (int i = 0; i < N; ++i) { cin >> h[i]; } vector<i64> w(N); for (int i = 0; i < N; ++i) { cin >> w[i]; } vector<int> L(N); vector<int> stk; for (int i = 0; i < N; ++i) { while (!stk.empty() && h[stk.back()] > h[i]) { stk.pop_back(); } L[i] = stk.empty() ? -1 : stk.back(); stk.push_back(i); } vector<i64> sum(N + 1); for (int i = 0; i < N; ++i) { sum[i + 1] = sum[i] + w[i]; } auto range_sum = [&](int l, int r) { return (sum[r] - sum[l]) % M; }; vector<i64> mono(N); for (int i = 0; i < N; ++i) { add(mono[i], C(h[i], w[i])); add(mono[i], F(h[i]) * w[i] % M * range_sum(L[i] + 1, i) % M); if (L[i] != -1) { add(mono[i], w[i] * mono[L[i]] % M); } } cout << accumulate(mono.begin(), mono.end(), 0LL) % M << "\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...