제출 #881895

#제출 시각아이디문제언어결과실행 시간메모리
8818951L1YAFancy Fence (CEOI20_fancyfence)C++17
100 / 100
22 ms6712 KiB
//1L1YA #include<bits/stdc++.h> using namespace std; #define ll long long #define Pb push_back #define dokme(x) cout << x << endl, exit(0) #define pii pair<int,int> #define F first #define S second #define endl '\n' #define sep ' ' #define all(x) x.begin(),x.end() #define FastIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define lc id<<1 #define rc lc|1 const ll mod=1e9+7; const ll oo=4e18; const int N=1e5+5; const int lg=23; ll n,in=(mod+1)/2,h[N],w[N],dp[N],lst[N],sum[N]; ll C(ll x){ x%=mod; return (x*(x-1)%mod*in%mod)%mod; } int main(){ FastIO cin >> n; for(int i=1;i<=n;i++) cin >> h[i]; for(int i=1;i<=n;i++) cin >> w[i],sum[i]=(sum[i-1]+w[i])%mod; vector<int> st; st.Pb(0); for(int i=1;i<=n;i++){ while(h[i]<=h[st.back()]) st.pop_back(); lst[i]=st.back(); st.Pb(i); } ll ans=0; for(int i=1;i<=n;i++){ ll W=(sum[i]-sum[lst[i]]+mod)%mod; ll p=C(W+1); p=(p-C((W-w[i]+1+mod)%mod)+mod)%mod; ans=(ans+p*C(h[i]+1)%mod)%mod; ans=(ans+dp[lst[i]]*w[i]%mod)%mod; dp[i]=(W*C(h[i]+1)%mod+dp[lst[i]])%mod; } cout << ans << endl; 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...