Submission #465837

#TimeUsernameProblemLanguageResultExecution timeMemory
465837ivan_tudorFancy Fence (CEOI20_fancyfence)C++14
100 / 100
78 ms5316 KiB
#include<bits/stdc++.h> using namespace std; const int MOD = 1e9+7; const unsigned long long N = 1e5+5; unsigned long long lgcput(unsigned long long b,unsigned long long p){ unsigned long long a = 1; while(p){ if(p & 1){ a *= b; a%=MOD; } b*=b; b%=MOD; p/=2; } return a; } unsigned long long cost(unsigned long long n){ return ((unsigned long long)(((unsigned long long)(n *(n+1)))%MOD) *(lgcput(2,MOD-2) % MOD)) %MOD ; } struct drept{ unsigned long long h,w; }; drept v[N]; unsigned long long stk[N]; unsigned long long nwc[N]; int main() { //freopen(".in","r",stdin); ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); unsigned long long n; cin>>n; for(unsigned long long i =1;i<=n;i++){ cin>>v[i].h; } for(unsigned long long i=1;i<=n;i++){ cin>>v[i].w; } unsigned long long ans = 0; unsigned long long nw = 0; unsigned long long vf = 0; nwc[0] = 0; for(unsigned long long i=1;i<=n;i++){ unsigned long long dlted = 0; while(vf>0 && v[stk[vf]].h >= v[i].h){ dlted += v[stk[vf]].w; dlted %= MOD; v[i].w %=MOD; vf--; } nw = ((unsigned long long)nwc[stk[vf]] + ((unsigned long long)cost(v[i].h) * dlted)%MOD ) %MOD; ans += ((unsigned long long) nw * v[i].w)%MOD; ans %= MOD; ans += ((unsigned long long)cost(v[i].h) * cost(v[i].w)) % MOD; ans %= MOD; nw += ((unsigned long long) cost(v[i].h) * v[i].w) % MOD; nw %= MOD; nwc[i] = nw; stk[++vf] = i; v[i].w += dlted; v[i].w%=MOD; } cout<<ans; 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...