제출 #129555

#제출 시각아이디문제언어결과실행 시간메모리
129555BTheroCandies (JOI18_candies)C++17
100 / 100
825 ms31352 KiB
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define pb push_back
#define mp make_pair
 
#define all(x) (x).begin(), (x).end()
 
#define fi first
#define se second
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef pair<ll, ll> pll;   
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
const int MAXN = (int)2e5 + 5;
const ll INF = (ll)1e18;
 
ll arr[MAXN], ans[MAXN];

int n;
 
pll rev(pll x) {
    return mp(x.se, x.fi);
}

void solve() {
    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        scanf("%lld", &arr[i]);
    }

    set<pll> S, S2;

    for (int i = 0; i < n; ++i) {
        S.insert(mp(arr[i], i));
        S2.insert(mp(i, arr[i]));
    }

    for (int i = 1; i <= (n + 1) / 2; ++i) {
        ans[i] = ans[i - 1] + S.rbegin() -> fi;
        auto it = S2.lower_bound(rev(*S.rbegin()));

        if (it == --S2.end()) {
            S.erase(rev(*S2.rbegin()));
            S2.erase(--S2.end());

            if (!S2.empty()) {
                S.erase(rev(*S2.rbegin()));
                S2.erase(--S2.end());
            }
        }
        else if (it == S2.begin()) {
            S.erase(rev(*S2.begin()));
            S2.erase(S2.begin());

            if (!S2.empty()) {
                S.erase(rev(*S2.begin()));
                S2.erase(S2.begin());
            }
        }
        else {
            --it;
            pll A = *it++;
            pll B = *it++;
            pll C = *it++;

            ll nw = A.se + C.se - B.se;
            S.erase(rev(A));
            S2.erase(A);
            S.erase(rev(B));
            S2.erase(B);
            S.erase(rev(C));
            S2.erase(C);
            S.insert(mp(nw, A.fi));
            S2.insert(mp(A.fi, nw));
        }
    }

    for (int i = 1; i <= (n + 1) / 2; ++i) {
        printf("%lld\n", ans[i]);
    }
}
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 
    int tt = 1;
 
    while (tt--) {
        solve();
    }
 
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

candies.cpp: In function 'void solve()':
candies.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
candies.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...