이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int m=1e9+7;
signed main(){
int n; cin>>n;
vector<int> h(n), w(n);
for (int i=0; i<n; i++) cin>>h[i];
for (int i=0; i<n; i++) cin>>w[i];
vector<int> sumLeft(n,0), sumRight(n,0);
stack<int> sL,sR;
for (int i=0; i<n; i++){
while (!sL.empty() and h[sL.top()]>h[i]){
sumLeft[i]+=(sumLeft[sL.top()]+w[sL.top()])%m;
sumLeft[i]%=m;
sL.pop();
}
sL.push(i);
}
for (int i=n-1; i>=0; i--){
while (!sR.empty() and h[sR.top()]>=h[i]){
sumRight[i]+=(sumRight[sR.top()]+w[sR.top()])%m;
sumRight[i]%=m;
sR.pop();
}
sR.push(i);
}
///rwgrgw
int ans=0;
for (int i=0; i<n; i++){
int hors = (sumLeft[i]*sumRight[i])%m + (sumLeft[i]*w[i])%m+(sumRight[i]*w[i])%m + ((w[i]*((w[i]-1))*(int)500000004)%m)%m + w[i]%m;
hors%=m;
int verts = ((h[i]*((h[i]-1))*(int)500000004)%m)%m + (h[i])%m;
verts%=m;
ans+=(hors*verts)%m;
ans%=m;
}
cout<<ans<<'\n';
}
# | 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... |