이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
const int MOD = 1'000'000'007;
const int MX = 400'005;
//long double PI = 3.14159265358979323846264338327950;
int main(){
cin.tie(0);ios_base::sync_with_stdio(0);
//freopen ("out.txt","w",stdout);
//int n_casos=1; cin>>n_casos;
//while(n_casos--) caso_teste();
int n; cin>>n;
ll h[n+1], w[n+1];
stack<pair<ll,ll>> s;
s.push(make_pair(0,0));//par (altura,largura)
ll ans=0;
for(int i=0; i<n; i++){
cin>>h[i];
}
for(int i=0; i<n; i++){
cin>>w[i];
}
h[n]=0; w[n]=0;
for(int i=0; i<n+1; i++){
ll largura;
while((s.top()).f>h[i]){
largura=s.top().s;
ll altura=s.top().f;
ll ALTURA=s.top().f;
s.pop();
altura=max(h[i],s.top().f);
ans+=( (((ALTURA*(ALTURA+1ll))/2ll)%MOD) * (((largura*(largura+1ll))/2ll)%MOD) )%MOD;
ans-=( (((altura*(altura+1ll))/2ll)%MOD) * (((largura*(largura+1ll))/2ll)%MOD) )%MOD;
//cout<<ALTURA<<' '<<altura<<' '<<ans<<'\n';
if(s.top().f>=h[i])s.top().s+=largura;
else w[i]+=largura;
}
if(h[i]==s.top().f){
s.top().s+=w[i];
}else{
s.push({h[i],w[i]});
}
}
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... |