Submission #61699

# Submission time Handle Problem Language Result Execution time Memory
61699 2018-07-26T11:08:47 Z mAng0 Candies (JOI18_candies) C++17
0 / 100
5 ms 524 KB
#include<bits/stdc++.h>
using namespace std;

using interval = pair<int, int>;
#define s first
#define e second

map<interval, long long> mp;

using qtype = pair<long long, interval>;
priority_queue<qtype> pq;

int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        long long x;
        scanf("%lld",&x);
        mp[{i, i}] = x;
        pq.push({x, {i, i}});
    }
    long long ans = 0;
    for(int i=0;i<(n+1)/2;i++){
        while(mp.find(pq.top().second) == mp.end()){
            //printf("bye: %d - %d, %lld\n", pq.top().second.s, pq.top().second.e, pq.top().first);
            pq.pop();
        }
        //printf("hi: %d - %d, %lld\n", pq.top().second.s, pq.top().second.e, pq.top().first);
        qtype top = pq.top();
        ans += top.first;
        interval tt = top.second;
        pq.pop();
        interval newtt = top.second;
        long long newval = -top.first;
        long long vall = top.first;
        auto pit = mp.find(tt);
        auto nit = pit; nit++;
        if(pit != mp.begin()){
            pit--;
            newtt.s = (*pit).first.s;
            newval += (*pit).second;
            //printf("del: %d - %d, %lld\n", (*pit).first.s, (*pit).first.e, (*pit).second);
            mp.erase(pit);
        }
        if(nit != mp.end()){
            newtt.e = (*nit).first.e;
            newval += (*nit).second;
            //printf("del: %d - %d, %lld\n", (*nit).first.s, (*nit).first.e, (*nit).second);
            mp.erase(nit);
        }
        //printf("del: %d - %d, %lld\n", tt.s, tt.e, vall);
        mp.erase(tt);
        mp[newtt] = newval;
        //printf("add: %d - %d, %lld\n", newtt.s, newtt.e, newval);
        pq.push({newval, newtt});
        printf("%lld\n", ans);
    }
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:35:19: warning: unused variable 'vall' [-Wunused-variable]
         long long vall = top.first;
                   ^~~~
candies.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
candies.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&x);
         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 524 KB Output isn't correct
2 Halted 0 ms 0 KB -