답안 #855944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855944 2023-10-02T11:08:38 Z 8pete8 Candies (JOI18_candies) C++14
0 / 100
1 ms 604 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define int long long
const int mxn=1e5,mod=29947,lg=25,inf=1e18;
int l[mxn+10],r[mxn+10];
bitset<mxn+10>del;
int32_t main(){
    fastio
    int n;cin>>n;
    vector<int>v(n);
    priority_queue<pii>pq;
    for(int i=1;i<=n;i++)cin>>v[i],pq.push({v[i],i}),l[i]=i-1,r[i]=i+1;
    int ans=0;
    for(int i=1;i<=(n+1)/2;i++){
        while(del[pq.top().s])pq.pop();
        ans+=pq.top().f;
        int cur=pq.top().s;
        cout<<ans<<'\n';
        pq.pop();
        del[l[cur]]=true;
        del[r[cur]]=true;
        v[cur]=v[l[cur]]+v[r[cur]]-v[cur];
        if(cur!=1&&cur!=n)pq.push({v[cur],cur});
        l[cur]=l[l[cur]];
        r[cur]=r[r[cur]];
        r[l[cur]]=cur;
        l[r[cur]]=cur;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -