Submission #558052

#TimeUsernameProblemLanguageResultExecution timeMemory
558052Tenis0206Fancy Fence (CEOI20_fancyfence)C++11
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int Mod = 1e9 + 7; int n; int h[100005],w[100005]; int sp[100005]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) { cin>>h[i]; } for(int i=1;i<=n;i++) { cin>>w[i]; sp[i] = (sp[i-1] + w[i]) % Mod; } stack<int> st,st_sum; st.push(0); long long sum = 0, rez = 0; for(int i=1;i<=n;i++) { while(h[i]<=h[st.top()]) { sum = (sum - st_sum.top() + Mod) % Mod; st_sum.pop(); st.pop(); } rez += 1LL * sum * w[i] % Mod; rez %= Mod; rez += w[i] * (w[i] + 1) / 2 % Mod * (h[i] * (h[i]+1) / 2 % Mod) % Mod; int c_sum = (sp[i] - sp[st.top()] + Mod) % Mod * (h[i] * (h[i] + 1) / 2 % Mod) % Mod; sum += c_sum; sum %= Mod; st_sum.push(c_sum); st.push(i); } cout<<rez<<'\n'; return 0; }
#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...