답안 #957567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957567 2024-04-04T03:43:26 Z parlimoos Candies (JOI18_candies) C++14
100 / 100
552 ms 30640 KB
//‌‌Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<ll , x>
#define endl '\n'

int n;
vector<ll> a;
multiset<arr(3)> ord , sgs;
ll o = 0;

void uSg(ll l , ll r , ll c){
    arr(3) d = {l , r , c};
    auto itr = sgs.find(d);
    ord.erase({(*itr)[2] , (*itr)[0] , (*itr)[1]});
    vector<arr(3)> dls;
    dls.pb({l , r , c});
    o += c , c = (-c);
    if(itr != sgs.bg()){
        --itr;
        c += (*itr)[2] , l = (*itr)[0];
        ord.erase({(*itr)[2] , (*itr)[0] , (*itr)[1]}) , dls.pb({(*itr)[0] , (*itr)[1] , (*itr)[2]});
        itr++;
    }else l = -1;
    if(itr != --sgs.end()){
        ++itr;
        c += (*itr)[2] , r = (*itr)[1];
        ord.erase({(*itr)[2] , (*itr)[0] , (*itr)[1]}) , dls.pb({(*itr)[0] , (*itr)[1] , (*itr)[2]});
        itr--;
    }else r = n;
    ord.insert({c , l , r}) , sgs.insert({l , r , c});
    for(auto &dl : dls) sgs.erase(dl);
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    for(int i = 0 ; i < n ; i++){
        int d;
        cin >> d;
        a.pb(d);
    }
    for(int i = 0 ; i < n ; i++){
        sgs.insert({i , i , a[i]}) , ord.insert({a[i] , i , i});
    }
    for(int i = 1 ; i <= ((n + 1) >> 1) ; i++){
        auto itr = --(ord.end());
        while((*itr)[1] == -1 or (*itr)[2] == n) --itr;
        ll l = (*itr)[1] , c = (*itr)[0] , r = (*itr)[2];
        uSg(l , r , c);
        cout << o << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 856 KB Output is correct
3 Correct 3 ms 752 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 2 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 856 KB Output is correct
3 Correct 3 ms 752 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 2 ms 616 KB Output is correct
21 Correct 547 ms 30408 KB Output is correct
22 Correct 552 ms 30388 KB Output is correct
23 Correct 481 ms 30592 KB Output is correct
24 Correct 273 ms 30392 KB Output is correct
25 Correct 249 ms 30116 KB Output is correct
26 Correct 256 ms 30172 KB Output is correct
27 Correct 271 ms 30444 KB Output is correct
28 Correct 253 ms 30404 KB Output is correct
29 Correct 264 ms 30508 KB Output is correct
30 Correct 286 ms 30404 KB Output is correct
31 Correct 279 ms 30640 KB Output is correct
32 Correct 274 ms 30392 KB Output is correct
33 Correct 356 ms 30152 KB Output is correct
34 Correct 349 ms 30148 KB Output is correct
35 Correct 362 ms 30240 KB Output is correct
36 Correct 514 ms 30396 KB Output is correct
37 Correct 491 ms 30412 KB Output is correct
38 Correct 476 ms 30532 KB Output is correct
39 Correct 267 ms 30136 KB Output is correct
40 Correct 263 ms 30408 KB Output is correct
41 Correct 247 ms 30260 KB Output is correct
42 Correct 249 ms 30504 KB Output is correct
43 Correct 254 ms 30404 KB Output is correct
44 Correct 259 ms 30412 KB Output is correct
45 Correct 284 ms 30508 KB Output is correct
46 Correct 265 ms 30356 KB Output is correct
47 Correct 274 ms 30460 KB Output is correct
48 Correct 336 ms 30116 KB Output is correct
49 Correct 376 ms 30084 KB Output is correct
50 Correct 382 ms 30152 KB Output is correct