Submission #442231

# Submission time Handle Problem Language Result Execution time Memory
442231 2021-07-07T10:14:39 Z cpp219 Candies (JOI18_candies) C++14
100 / 100
634 ms 27076 KB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e5 + 3;
const ll Log2 = 20;
const ll inf = 1e16 + 7;
typedef pair<ll,ll> LL;

ll n,a[N],val[N];

set<LL> s;
set<ll> num;


int main(){
    ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    cin>>n; val[0] = val[n + 1] = -inf; num.insert(0); num.insert(n + 1);
    for (ll i = 1;i <= n;i++) cin>>a[i],s.insert({a[i],i}),val[i] = a[i],num.insert(i);
    ll cur = 0,p;
    for (ll i = 1;i <= (n + 1)/2;i++){
        LL t = *s.rbegin(); s.erase(prev(s.end()));
        cur += t.fs; ll now = t.sc; num.erase(now);
        auto it1 = num.lower_bound(now),it2 = num.upper_bound(now);
        ll p = now,q = now;
        p = *prev(it1); q = *it2;
        s.erase({val[p],p}); s.erase({val[q],q});
        val[p] += val[q] - t.fs; num.erase(q); s.insert({val[p],p});
        cout<<cur<<"\n";
    }
}

Compilation message

candies.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
candies.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
candies.cpp: In function 'int main()':
candies.cpp:31:16: warning: unused variable 'p' [-Wunused-variable]
   31 |     ll cur = 0,p;
      |                ^
candies.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 3 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 2 ms 588 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 2 ms 588 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 3 ms 588 KB Output is correct
17 Correct 3 ms 588 KB Output is correct
18 Correct 2 ms 588 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 2 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 3 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 2 ms 588 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 2 ms 588 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 3 ms 588 KB Output is correct
17 Correct 3 ms 588 KB Output is correct
18 Correct 2 ms 588 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 2 ms 588 KB Output is correct
21 Correct 617 ms 26816 KB Output is correct
22 Correct 590 ms 26820 KB Output is correct
23 Correct 634 ms 26812 KB Output is correct
24 Correct 263 ms 26820 KB Output is correct
25 Correct 269 ms 26744 KB Output is correct
26 Correct 268 ms 26840 KB Output is correct
27 Correct 285 ms 27076 KB Output is correct
28 Correct 285 ms 26820 KB Output is correct
29 Correct 293 ms 26796 KB Output is correct
30 Correct 302 ms 26796 KB Output is correct
31 Correct 296 ms 26864 KB Output is correct
32 Correct 301 ms 26820 KB Output is correct
33 Correct 449 ms 26896 KB Output is correct
34 Correct 425 ms 26820 KB Output is correct
35 Correct 451 ms 26796 KB Output is correct
36 Correct 583 ms 26760 KB Output is correct
37 Correct 579 ms 26796 KB Output is correct
38 Correct 596 ms 26844 KB Output is correct
39 Correct 268 ms 26804 KB Output is correct
40 Correct 259 ms 26716 KB Output is correct
41 Correct 269 ms 26868 KB Output is correct
42 Correct 287 ms 26848 KB Output is correct
43 Correct 279 ms 26820 KB Output is correct
44 Correct 295 ms 26828 KB Output is correct
45 Correct 305 ms 26788 KB Output is correct
46 Correct 295 ms 26908 KB Output is correct
47 Correct 299 ms 26820 KB Output is correct
48 Correct 413 ms 27036 KB Output is correct
49 Correct 431 ms 26820 KB Output is correct
50 Correct 428 ms 26900 KB Output is correct