Submission #942373

#TimeUsernameProblemLanguageResultExecution timeMemory
942373batsukh2006Fancy Fence (CEOI20_fancyfence)C++17
15 / 100
23 ms3676 KiB
#include<iostream> #include<stdio.h> #include<math.h> #include<map> #include<string> #include<algorithm> #include<vector> #include<string.h> #include<utility> #include<set> #include<cmath> #include<queue> #include<deque> #include<functional> #include<stack> #include<limits.h> #include<iomanip> #include<unordered_map> using namespace std; #define MOD 1000000007 #define int long long #define endl '\n' int cal(int a, int b){ int f=(a*(a+1))%MOD*((MOD+1)/2)%MOD; int s=(b*(b+1))%MOD*((MOD+1)/2)%MOD; return (f*s)%MOD; } void solve(){ int n; cin>>n; vector<int> h(n+1),w(n+1); for(int i=1; i<=n; i++) cin>>h[i]; for(int i=1; i<=n; i++) cin>>w[i]; int ans=0,sum=0; for(int i=1; i<=n; i++){ if(h[i]>h[i-1]) sum=w[i]; else sum=(sum+w[i])%MOD; ans=(ans+cal(sum,h[i]))%MOD; ans=(ans-cal(sum-w[i],h[i])+MOD)%MOD; } sum=0; int cur=0; for(int i=n; i>=1; i--){ if(h[i]>h[i+1]) sum=w[i]; else sum=(sum+w[i])%MOD; if(h[i]==h[i+1]) cur=(cur+w[i])%MOD; else cur=w[i]; if(sum!=cur){ ans=(ans+cal(sum,h[i]))%MOD; ans=(ans-cal(cur,h[i])+MOD)%MOD; ans=(ans-cal(sum-w[i],h[i])+MOD)%MOD; } } cout<<ans; } signed main(){ // freopen("hps.in", "r", stdin); // freopen("hps.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); cout<<endl; } 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...