Submission #1002123

#TimeUsernameProblemLanguageResultExecution timeMemory
1002123alecurseFancy Fence (CEOI20_fancyfence)C++17
12 / 100
1 ms600 KiB
#include <bits/stdc++.h> #define ll long long int #define mp make_pair using namespace std; ll mod = 1e9+7; int main() { ll N; cin>>N; vector<ll> prefix(N+1); vector<ll> H(N+1), W(N+1); ll res=0; for(ll i=1;i<=N;i++) { cin>>H[i]; } for(ll i=1;i<=N;i++) { cin>>W[i]; prefix[i]=prefix[i-1]+W[i]; } vector<pair<ll,ll> > v(N); set<ll> s; for(ll i=1;i<=N;i++) { s.insert(i); v[i-1]=mp(H[i],i); } sort(v.rbegin(),v.rend()); s.insert(0); s.insert(N+1); for(ll t=0;t<N;t++) { ll index=v[t].second; s.erase(index); auto it= s.upper_bound(index); ll wd = prefix[*it-1]-prefix[index]; it=prev(it,1); ll ws = prefix[index-1]-prefix[*it]; ll w = W[index]; ll h = H[index]; ll sum=h*(h+(ll)1)/(ll)2; ll sumw=w*(w+(ll)1)/(ll)2; sum%=mod; sumw%=mod; ll toadd=0; toadd+=(ws*w)%mod; toadd%=mod; toadd+=(wd*w)%mod; toadd%=mod; toadd+=(wd*ws)%mod; toadd%=mod; toadd+=sumw; toadd%=mod; toadd*=sum; toadd%=mod; res+=toadd; res%=mod; } cout<<res; }
#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...