이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |