Submission #502435

#TimeUsernameProblemLanguageResultExecution timeMemory
502435Fireball0424Fancy Fence (CEOI20_fancyfence)C++14
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> #define int long long #define fr first #define sc second #define pii pair<int,int> using namespace std; const int mod = 1e9 + 7; int modpow(int a, int b){ if(b == 0) return 1; int res = modpow(a, b / 2); res = (res * res) % mod; if(b & 1) res = (res * a) % mod; return res; } int cal(int x){ return (x * (x + 1) / 2) % mod; } void solve(){ int n; cin >> n; vector<int> h(n + 1, 0), w(n + 1, 0); for(int i = 1; i <= n; ++i) cin >> h[i]; for(int i = 1; i <= n; ++i) cin >> w[i]; stack<int> stk; stk.push(0); int ans = 0; vector<int> dp(n + 1, 0), pre(n + 1, 0); for(int i = 1; i <= n; ++i) pre[i] = pre[i-1] + w[i]; for(int i = 1; i <= n; ++i) { while (h[stk.top()] >= h[i]) stk.pop(); dp[i] = dp[stk.top()] + cal(h[i]) * cal(pre[i] - pre[stk.top()]); ans += dp[stk.top()] * w[i] + cal(h[i]) * (pre[i - 1] - pre[stk.top()]) * w[i] + cal(h[i]) * cal(w[i]); stk.push(i); } cout << ans << endl; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); //freopen("bbreeds.in", "r"); //freopen("bbreeds.out", "w"); solve(); }
#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...