Submission #576725

#TimeUsernameProblemLanguageResultExecution timeMemory
576725timreizinFancy Fence (CEOI20_fancyfence)C++17
12 / 100
1 ms340 KiB
#include <iostream> #include <vector> #include <array> #include <algorithm> #include <iomanip> #include <cmath> #include <stack> #include <numeric> using namespace std; using ll = long long; const ll MOD = 1e9 + 7; ll asum(ll n) { return ((n * (n + 1)) / 2) % MOD; } int main() { cin.tie(0)->sync_with_stdio(0); //freopen("/Users/timreizin/Downloads/sample/input1.txt", "r", stdin); int n; cin >> n; vector<ll> h(n), w(n); for (ll &i : h) cin >> i; for (ll &i : w) cin >> i; vector<ll> pref(n + 1); partial_sum(w.begin(), w.end(), pref.begin() + 1); vector<int> sl(n, -1), sr(n, n); stack<int> help; for (int i = 0; i < n; ++i) { while (!help.empty() && h[help.top()] >= h[i]) help.pop(); if (!help.empty()) sl[i] = help.top(); help.push(i); } while (!help.empty()) help.pop(); for (int i = n - 1; i >= 0; --i) { while (!help.empty() && h[help.top()] > h[i]) help.pop(); if (!help.empty()) sr[i] = help.top(); help.push(i); } ll res = 0; for (int i = 0; i < n; ++i) { if (i + 1 < n) { ll sum = w[i] * w[i + 1] % MOD - 1; if (sum < 0) sum += MOD; res = (res + sum * min(h[i], h[i + 1])) % MOD; } res = (res + asum(h[i]) * asum(w[i])) % MOD; ll l1 = (pref[i] - pref[sl[i] + 1]) % MOD; ll l2 = (pref[sr[i]] - pref[i + 1]) % MOD; ll sum = (l1 + 1) * (l2 + 1) % MOD - 1; if (sum < 0) sum += MOD; res = (res + sum * asum(h[i])) % MOD; } cout << res; return 0; } /* 2 2 2 2 2 */
#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...