Submission #703388

#TimeUsernameProblemLanguageResultExecution timeMemory
703388Darren0724Fancy Fence (CEOI20_fancyfence)C++17
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define all(x) x.begin(),x.end() const int mod=1e9+7; int cal(int left,int right,int up,int down){ int width=right-left+1; width%=mod; int ans=width*(width-1)/2; ans%=mod; int tmp=up*(up+1)-down*(down+1); tmp/=2; //cout<<left<<' '<<right<<' '<<up<<' '<<down<<' '<<ans*tmp<<endl; return ans*tmp%mod; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n;cin>>n; vector<int> a(n+1),b(n+1); for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n;i++){ cin>>b[i]; b[i]+=b[i-1]; } int ans=0; vector<int> v; v.push_back(0); for(int i=1;i<=n;i++){ while(a[i]<a[v.back()]){ //cout<<"OK"<<endl; ans+=cal(b[v.back()-1],b[i-1],a[v.back()],a[i]); ans%=mod; v.pop_back(); } if(a[i]>a[v.back()]){ v.push_back(i); } } while(v.size()>1){ int tmp=v.back(); v.pop_back(); ans+=cal(b[tmp-1],b[n],a[tmp],a[v.back()]); ans%=mod; } cout<<ans<<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...