Submission #468378

#TimeUsernameProblemLanguageResultExecution timeMemory
468378thomas_liFancy Fence (CEOI20_fancyfence)C++17
12 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pi; const int MM = 1e5+5,MOD = 1e9+7,inv2 = 500000004; int n,h[MM],w[MM],psa[MM],dp[MM]; int c2(int x){ int val = (1ll*x*((x-1+MOD)%MOD) % MOD) * inv2 % MOD; return (val+x)% MOD; } int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n; for(int i = 1; i <= n; i++) cin >> h[i]; for(int i = 1; i <= n; i++) cin >> w[i],psa[i] = (psa[i-1] + w[i]) % MOD; stack<int> st; st.push(0); int ans = 0; for(int i = 1; i <= n; i++){ while(st.size() && h[st.top()] >= h[i]) st.pop(); int j = st.top(); dp[i] = dp[j]; dp[i] = (dp[i] + 1ll*w[j]*c2(h[j]) % MOD)%MOD; dp[i] = (dp[i] + 1ll*((psa[i-1] - psa[j]+MOD)%MOD)*c2(h[i]) % MOD) % MOD; ans = ((ans + 1ll*dp[i]*w[i] % MOD)%MOD + 1ll*c2(w[i])*c2(h[i]) % MOD); st.push(i); } cout << ans << "\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...