이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int DIM = 2E5+7;
const ll MOD = 1E9+7;
ll W[DIM],H[DIM];
int solve(){
ll res = 0,sum = 0;
stack<pair<ll,ll> > S;
int n;
cin>>n;
for(int i = 1;i<=n;++i)
cin>>H[i];
for(int i = 1;i<=n;++i)
cin>>W[i];
for(int i = 1;i<=n;++i){
ll h = H[i],w = W[i];
ll cur = 0;
while(!S.empty() && S.top().first>=h){
cur+=S.top().second;
sum= (sum-S.top().first*(S.top().first+1)/2%MOD*S.top().second)%MOD;
sum = (sum+h*(h+1)/2%MOD*S.top().second)%MOD;
S.pop();
}
res = (res+w*sum)%MOD;
ll mu = h*(h+1)/2%MOD;
res = (res+w*(w+1)/2%MOD*mu%MOD)%MOD;
cur+=w;
sum = (sum+h*(h+1)/2%MOD*w)%MOD;
S.push({h,cur%MOD});
}
if (res<0)res+=MOD;
cout<<res<<endl;
return 1;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t;
t = 1;
while(t--)
assert(solve());
return 0;
}
# | 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... |