Submission #372754

#TimeUsernameProblemLanguageResultExecution timeMemory
372754jenkinsserFancy Fence (CEOI20_fancyfence)C++17
100 / 100
36 ms6140 KiB
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define st first #define nd second #define pii pair<int,int> #define piii pair<int,pii> #define sp " " #define nl "\n" #define all(x) x.begin(),x.end() #define fastio() ios_base::sync_with_stdio(0);cin.tie(0); #define ll long long #define int ll using namespace std; const int N = 100005; const int INF = 1e9+7; const int mod = 1e9+7; const int inv2 = 500000004; int n,w[N],h[N],ans; int comb2(int x){ return x*(x-1)%mod*inv2%mod; } int32_t main(){ fastio() cin >> n; for(int i=0;i<n;i++) cin >> h[i]; for(int i=0;i<n;i++) cin >> w[i]; vector<pii> vec; vec.pb({0,0}); for(int i=0;i<=n;i++){ int len=0; while(vec.back().st>h[i]){ int prv=max(h[i],vec[(int)vec.size()-2].st); int dif=vec.back().st-prv; len=(len+vec.back().nd)%mod; vec.pop_back(); ans+=((comb2(dif+1)+(dif*prv)%mod))*comb2(len+1); ans%=mod; } if(vec.back().st==h[i]){ vec.back().nd=(vec.back().nd+len+w[i])%mod; } else{ vec.pb({h[i],(len+w[i])%mod}); } } cout << ans << nl; }
#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...