QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#138241#6626. Real Mountainsblackyuki#0 0ms3596kbC++141.9kb2023-08-11 10:51:352024-07-04 01:36:07

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 01:36:07]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3596kb
  • [2023-08-11 10:51:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define pb emplace_back
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
const ll inf=1001001001001001001;
int main(){
    ll n,ans=0;cin>>n;
    vi v(n);rep(i,n)cin>>v[i];
    vi srt=v;dupli(srt);
    vvi g(srt.size());
    rep(i,n)g[lb(srt,v[i])].pb(i);
    P rng(1,n-1);
    set<ll> idx;
    rep(i,srt.size()-1){
        ll x=srt[i],y=srt[i+1];
        while(rng.fi<=rng.se&&v[rng.fi-1]<=max(x,v[rng.fi])){
            idx.erase(rng.fi);
            chmax(v[rng.fi],x);
            rng.fi++;
        }
        while(rng.fi<=rng.se&&v[rng.se+1]<=max(x,v[rng.se])){
            idx.erase(rng.se);
            chmax(v[rng.se],x);
            rng.se--;
        }
        if(rng.fi>rng.se)break;
        for(ll j:g[i])if(rng.fi<=j&&j<=rng.se){
            idx.insert(j);
        }
        ll cnt=idx.size();
        if(cnt==0)continue;
        ll s1=y-x,s2=(x+y-1)*(y-x)/2;
        ll l=inf,r=inf;
        ll a=*idx.begin(),b;
        auto itr=idx.end();itr--;b=*itr;
        rep(j,a)if(v[j]>x)chmin(l,v[j]);
        REP(j,b+1,n)if(v[j]>x)chmin(r,v[j]);
        if(cnt==1){
            ans+=(l+r)*s1+s2;
        }
        if(cnt>=2){
            ans+=(2*cnt-3+l+r+y)*s1+(2*cnt-3+cnt)*s2;
        }
    }
    out(ans);
}


Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3596kb

input:

3
29 9 9

output:

1573275946310470694

result:

wrong answer 1st numbers differ - expected: '0', found: '1573275946310470694'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%