Submission #855947

# Submission time Handle Problem Language Result Execution time Memory
855947 2023-10-02T11:11:29 Z 8pete8 Candies (JOI18_candies) C++14
100 / 100
80 ms 12508 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=2*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+2);
    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;
    v[0]=v[n+1]=-inf;
    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];
        pq.push({v[cur],cur});
        l[cur]=l[l[cur]];
        r[cur]=r[r[cur]];
        r[l[cur]]=cur;
        l[r[cur]]=cur;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2620 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 3 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2620 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 3 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 68 ms 10692 KB Output is correct
22 Correct 70 ms 12180 KB Output is correct
23 Correct 68 ms 11784 KB Output is correct
24 Correct 56 ms 11716 KB Output is correct
25 Correct 70 ms 12304 KB Output is correct
26 Correct 56 ms 11716 KB Output is correct
27 Correct 62 ms 11712 KB Output is correct
28 Correct 62 ms 12484 KB Output is correct
29 Correct 70 ms 11908 KB Output is correct
30 Correct 63 ms 12388 KB Output is correct
31 Correct 61 ms 11840 KB Output is correct
32 Correct 63 ms 11940 KB Output is correct
33 Correct 66 ms 11924 KB Output is correct
34 Correct 65 ms 11464 KB Output is correct
35 Correct 67 ms 11904 KB Output is correct
36 Correct 69 ms 11644 KB Output is correct
37 Correct 72 ms 11836 KB Output is correct
38 Correct 68 ms 11632 KB Output is correct
39 Correct 56 ms 12004 KB Output is correct
40 Correct 59 ms 12416 KB Output is correct
41 Correct 57 ms 11716 KB Output is correct
42 Correct 63 ms 12508 KB Output is correct
43 Correct 65 ms 11868 KB Output is correct
44 Correct 63 ms 11720 KB Output is correct
45 Correct 71 ms 11712 KB Output is correct
46 Correct 62 ms 11716 KB Output is correct
47 Correct 63 ms 12240 KB Output is correct
48 Correct 80 ms 11696 KB Output is correct
49 Correct 64 ms 12224 KB Output is correct
50 Correct 64 ms 11460 KB Output is correct