Submission #782515

#TimeUsernameProblemLanguageResultExecution timeMemory
782515t6twotwoFancy Fence (CEOI20_fancyfence)C++17
100 / 100
27 ms4184 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int mod = 1e9 + 7; constexpr int i2 = 500000004; constexpr int i6 = 166666668; int mul(int a, int b) { return 1LL * a * b % mod; } void add(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } void sub(int &a, int b) { a -= b; if (a < 0) { a += mod; } } int f(int n) { return mul(i2, mul(n, n + 1)); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int> h(N), w(N); for (int &x : h) { cin >> x; } for (int &x : w) { cin >> x; } int ans = 0, s = 0; vector<array<int, 2>> stk; for (int i = 0; i < N; i++) { add(ans, mul(f(h[i]), f(w[i]))); int t = w[i]; while (!stk.empty() && stk.back()[0] >= h[i]) { sub(s, mul(f(stk.back()[0]), stk.back()[1])); add(t, stk.back()[1]); stk.pop_back(); } add(s, mul(f(h[i]), t)); add(ans, mul(w[i], s)); sub(ans, mul(f(h[i]), mul(w[i], w[i]))); stk.push_back({h[i], t}); } cout << ans << "\n"; return 6/22; }
#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...