QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#547653#7067. The Great Wallucup-team3474WA 1ms5908kbC++201.7kb2024-09-05 01:10:042024-09-05 01:10:05

Judging History

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

  • [2024-09-05 01:10:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5908kb
  • [2024-09-05 01:10:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1919810;
typedef long long ll;
typedef pair<ll,ll> PII;
ll n,m,k;
ll a[N],b[N];
char s[N];
ll ans[N];


typedef struct{
    int l,r;
    ll mn,mx;
}Node;
void __(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    vector<Node> v;
    int l=1;
    for(int i=2;i<=n;i++){
        if(a[i]<a[i-1]){
            v.push_back({l,i-1,a[l],a[i-1]});
            l=i;
        } 
    }
    v.push_back({l,n,a[l],a[n]});
    int t=v.size();
    // cout<<t<<endl;
    priority_queue<ll,vector<ll>,greater<ll>> q;
    // for(int i=1;i<=n;i++){
        for(auto [x,y,u,uu]:v){
            for(int j=x+1;j<=y;j++){
                q.push(a[j]-a[j-1]);
                ans[t]+=(a[j]-a[j-1]);
            }
        }
    // }
    for(int i=t+1;i<=n;i++){
        ans[i]=ans[i-1]-q.top();
        q.pop();
    }
    vector<Node> vv;
    for(int i=t-1;i>=1;i--){
        ll mn=1e18;
        ll mnt;
        for(int j=1;j<v.size();j++){
            ll res=v[j].mx+v[j-1].mx-v[j].mn-v[j-1].mn-(max(v[j].mx,v[j-1].mx)-min(v[j].mn,v[j-1].mn));
            if(res<mn){
                mn=res;
                mnt=j;
            }
        }
        // cout<<mn<<endl;
        ans[i]=ans[i+1]-mn;
        for(int j=0;j<mnt-1;j++) vv.push_back(v[j]);
        vv.push_back({v[mnt-1].l,v[mnt].r,min(v[mnt-1].mn,v[mnt].mn),max(v[mnt-1].mx,v[mnt].mx)});
        for(int j=mnt+1;j<v.size();j++) vv.push_back(v[j]);
        v=vv;
        vv.clear();
    }
    for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
}


int main(){
    int _=1;
    // cin>>_;
    while(_--){
        __();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5848kb

input:

5
1 2 3 4 5

output:

4
3
2
1
0

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 5792kb

input:

5
1 2 1 2 1

output:

1
2
2
1
0

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5908kb

input:

6
1 1 4 5 1 4

output:

4
7
7
6
3
0

result:

wrong answer 4th lines differ - expected: '7', found: '6'