# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647027 | jamielim | Fancy Fence (CEOI20_fancyfence) | C++14 | 32 ms | 3520 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;
int h[100005],w[100005];
inline ll choose2(ll x){
return ((x)*(x-1)/2)%MOD;
}
int main(){
//freopen("sample/input1.txt","r",stdin);
scanf("%d",&n);
for(int i=0;i<n;i++)scanf("%d",&h[i]);
for(int i=0;i<n;i++)scanf("%d",&w[i]);
ll ans=0;
vector<pair<ll,ll> > stk;
stk.pb(0,0);
ll cur=0;
for(int i=0;i<n;i++){
ll sum=0;
while(stk.back().fi>h[i]){
ii p=stk.back();stk.pop_back();
cur-=((p.se%MOD)*choose2(p.fi+1))%MOD;
cur%=MOD;
sum+=p.se;
}
cur+=((sum%MOD)*choose2(h[i]+1))%MOD;
cur%=MOD;cur+=MOD;cur%=MOD;
ans+=(cur*(ll)(w[i]))%MOD; // left side is strictly from previous block, right side is (,] of current block
ans%=MOD;
//printf("a' %lld\n",ans);
ans+=((choose2(h[i]+1)%MOD)*(choose2(w[i]+1)%MOD))%MOD; // left side is within current block
ans%=MOD;
//printf("a %lld\n",ans);
cur+=((w[i]%MOD)*choose2(h[i]+1))%MOD;
stk.pb(h[i],sum+w[i]);
}
printf("%lld",((ans%MOD)+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... |