# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647115 | jamielim | Fancy Fence (CEOI20_fancyfence) | C++14 | 41 ms | 6364 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;
int n;
ll h[100005],w[100005],p[100005];
int l[100005],r[100005];
inline ll choose2(ll x){
x%=MOD;
return ((x)*(x-1)/2)%MOD;
}
int main(){
//freopen("sample/input1.txt","r",stdin);
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%lld",&h[i]);
for(int i=1;i<=n;i++){
scanf("%lld",&w[i]);
p[i]=p[i-1]+w[i];
p[i]%=MOD;
}
vector<ll> stk;
stk.pb(0);
for(int i=1;i<=n;i++){
while(h[stk.back()]>=h[i]){
stk.pop_back();
}
l[i]=stk.back()+1;
stk.pb(i);
}
stk.clear();
stk.pb(n+1);
for(int i=n;i>=1;i--){
while(h[stk.back()]>h[i]){
stk.pop_back();
}
r[i]=stk.back()-1;
stk.pb(i);
}
ll ans=0;
for(int i=1;i<=n;i++){
ll cur=((p[r[i]]-p[i-1])%MOD)*((p[i]-p[l[i]-1])%MOD)-choose2(w[i])%MOD;
cur%=MOD;
cur*=choose2(h[i]+1);
ans+=cur%MOD;
ans%=MOD;
}
printf("%lld",(ans+MOD)%MOD);
}
Compilation message (stderr)
# | 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... |