Submission #458030

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