이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |