Submission #390418

#TimeUsernameProblemLanguageResultExecution timeMemory
390418BJoozzFancy Fence (CEOI20_fancyfence)C++14
30 / 100
100 ms5444 KiB
#include<bits/stdc++.h> using namespace std; #define X first #define Y second #define pb push_back #define int long long const int MAX=1e5+3,mod=1e9+7; int dp[MAX]; void maxx(int &a,int b){if(b>a) a=b;} void minn(int &a,int b){if(b<a) a=b;} void PL(int &a,int b){a+=b;if(a>=mod) a-=mod;} int b[MAX]; int a[MAX]; int D[MAX]; int gs(int x){ return (x*(x+1)/2)%mod; } signed main(){ int n; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } int ans=0; int top=0; for(int i=1,x;i<=n;i++){ cin>>x; b[i]=b[i-1]+x; while(a[i]<a[D[top]]) D[top]--; int u=D[top]; dp[i]=( gs(a[i])*(b[i]-b[u])+dp[u] )%mod; (ans+=dp[u]*x+gs(a[i])*gs(b[i]-b[u]))%=mod; D[++top]=i; } cout<<ans; }
#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...