Submission #404745

#TimeUsernameProblemLanguageResultExecution timeMemory
404745SirCovidThe19thFancy Fence (CEOI20_fancyfence)C++14
100 / 100
105 ms6084 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod (ll)1000000007 ll m(ll a, ll b){ a %= mod; b %= mod; return (a*b)%mod; } ll m(ll a, ll b, ll c){ a %= mod; b %= mod; c %= mod; return m(m(a, b), c); } ll sum(ll x){ return ((x*(x+1))/2)%mod; } int main(){ ll n, ans; cin >> n; ll h[n+1], w[n+1], p[n+1], dp[n+1]; h[0] = 0; p[0] = 0; dp[0] = 0, ans = 0; for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i <= n; i++) cin >> w[i]; for (int i = 1; i <= n; i++) p[i] = p[i-1]+w[i]; stack<ll> stk; stk.push(0); for (int i = 1; i <= n; i++){ while (!stk.empty() and h[stk.top()] >= h[i]) stk.pop(); dp[i] = dp[stk.top()] + m(sum(h[i]), (p[i]-p[stk.top()])); ans += m(dp[stk.top()], w[i]) + m(sum(h[i]), (p[i-1]-p[stk.top()]), w[i]) + m(sum(h[i]), sum(w[i])); dp[i] %= mod; ans %= mod; stk.push(i); } cout<<ans; }
#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...