Submission #1059109

#TimeUsernameProblemLanguageResultExecution timeMemory
1059109DucNguyen2007Fancy Fence (CEOI20_fancyfence)C++14
0 / 100
1 ms2524 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<int,int> #define pll pair<ll,ll> #define fi first #define se second const int maxN=1e5+5,MOD=1e9+7,REVMOD=250000002; const ll inf=2e18; int n,l[maxN+1],r[maxN+1]; ll h[maxN+1],w[maxN+1],s[maxN+1]; stack<int> st; void clr() { while(!st.empty()) { st.pop(); } } ll mul(ll x,ll y) { return (x*y)%MOD; } ll sc(ll x1,ll x2) { ll tmp=mul(x1+1,x2+1); tmp--; if(tmp<0) { tmp+=MOD; } return tmp; } ll calc(ll n,ll m) { return mul(mul(mul(1LL*n,1LL*(n+1)),mul(1LL*m,1LL*(m+1))),REVMOD); } ll get(ll x1,ll x2,int i) { return mul(mul(w[i]-1,x1+x2)+sc(x1,x2),h[i]); } int main() { //freopen("","r",stdin); //freopen("","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; for(int i=1;i<=n;i++) { cin>>h[i]; } s[0]=0; for(int i=1;i<=n;i++) { cin>>w[i]; s[i]=(s[i-1]+w[i])%MOD; } clr(); for(int i=1;i<=n;i++) { while(!st.empty()&&h[st.top()]>=h[i]) { st.pop(); } if(st.empty()) { l[i]=1; } else l[i]=st.top()+1; st.push(i); } clr(); for(int i=n;i>=1;i--) { while(!st.empty()&&h[st.top()]>h[i]) { st.pop(); } if(st.empty()) { r[i]=n; } else r[i]=st.top()-1; st.push(i); } ll ans=0; for(int i=1;i<=n;i++) { ll tmp1=s[i-1]-s[l[i]-1],tmp2=s[r[i]]-s[i]; ans=(ans+get(tmp1,tmp2,i))%MOD; ans=(ans+calc(h[i],w[i]))%MOD; } cout<<ans; } /*2 1 2 1 2 */
#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...