Submission #759008

#TimeUsernameProblemLanguageResultExecution timeMemory
759008ymmFancy Fence (CEOI20_fancyfence)C++17
12 / 100
1 ms348 KiB
#include <bits/stdc++.h> #define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x) #define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x) typedef long long ll; typedef std::pair<int, int> pii; typedef std::pair<ll , ll > pll; using namespace std; const int mod = 1e9+7; const int N = 100'010; int lft[N], rgt[N]; ll h[N], w[N], ps[N]; int n; ll solve(int l, int r, int i, ll hx) { if (l >= r) return 0; ll x = h[i] - hx; ll y = ps[r] - ps[l]; ll ans = 0; ans += (x*(x+1)/2 % mod) * (y*(y+1)/2 % mod); ans += (x * hx % mod) * (y*(y+1)/2 % mod); ans += solve(l, i, lft[i], h[i]); ans += solve(i+1, r, rgt[i], h[i]); ans %= mod; return ans; } int main() { cin.tie(0) -> sync_with_stdio(false); cin >> n; Loop (i,0,n) cin >> h[i]; Loop (i,0,n) { cin >> w[i]; ps[i+1] = ps[i] + w[i]; } vector<int> vec; Loop (i,0,n) { int lst = -1; while (vec.size() && h[vec.back()] > h[i]) { lst = vec.back(); vec.pop_back(); } lft[i] = lst; if (vec.size()) rgt[vec.back()] = i; vec.push_back(i); } cout << solve(0, n, vec[0], 0) << '\n'; }
#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...