Submission #390429

#TimeUsernameProblemLanguageResultExecution timeMemory
390429BJoozzFancy Fence (CEOI20_fancyfence)C++14
25 / 100
30 ms5440 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(){ ios::sync_with_stdio(0);cin.tie(0); //freopen("A.inp","r",stdin); 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)%mod; while(a[i]<a[D[top]]) 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(x)+x*(b[i-1]-b[u])%mod) )%=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...