Submission #276374

#TimeUsernameProblemLanguageResultExecution timeMemory
276374sjimedHappiness (Balkan15_HAPPINESS)C++14
Compilation error
0 ms0 KiB
#include "happiness.h" #include<bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(false); cin.tie(0); #define fi first #define se second #define em emplace #define eb emplace_back #define all(v) (v).begin(), (v).end() #define mp make_pair typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int inf = 1e9; const ll INF = 1e18; struct Node { ll v, lz; int l, r; Node() { v = 0; lz = 0; l = r = 0; } }; ll sz = 0; ll n, m; map<ll,int> chk; Node tree[20202020]; void update(int &node, ll &s, ll &e, ll &l, ll &r, ll &x) { if(r < s || e < l) return; if(l <= s && e <= r) { tree[node].v += x; tree[node].lz += x; return; } if(tree[node].l == 0) { tree[node].l = sz++; tree[tree[node].l].v = INF - (s+e)/2; } if(tree[node].r == 0) { tree[node].r = sz++; tree[tree[node].r].v = INF - e; } update(tree[node].l, s, (s+e)/2, l, r, x); update(tree[node].r, (s+e)/2+1, e, l, r, x); tree[node].v = min(tree[tree[node].l].v, tree[tree[node].r].v) + tree[node].lz; } bool init(int coinsCount, long long maxCoinSize, long long coins[]) { n = coinsCount; m = maxCoinSize + 1; tree[0].v = INF - m; sz++; for(int i=0; i<n; i++) { if(chk.find(coins[i]) == chk.end()) update(0, 0, m, coins[i], coins[i], -INF); update(0, 0, m, coins[i]+1, m, coins[i]); chk[coins[i]]++; } return tree[0].v >= -1; } bool is_happy(int event, int coinsCount, long long coins[]) { n = coinsCount; for(int i=0; i<n; i++) { if(chk.find(coins[i]) != chk.end() && chk[coins[i]] == 1 && event == -1) update(0, 0, m, coins[i], coins[i], INF); if((chk.find(coins[i]) == chk.end() || chk[coins[i]] == 0) && event == 1) update(0, 0, m, coins[i], coins[i], -INF); if(event == 1) update(0, 0, m, coins[i]+1, m, coins[i]); else update(0, 0, m, coins[i]+1, m, -coins[i]); chk[coins[i]] += event; } return tree[0].v >= -1; }

Compilation message (stderr)

happiness.cpp: In function 'void update(int&, ll&, ll&, ll&, ll&, ll&)':
happiness.cpp:53:31: error: cannot bind non-const lvalue reference of type 'll&' {aka 'long long int&'} to an rvalue of type 'll' {aka 'long long int'}
   53 |  update(tree[node].l, s, (s+e)/2, l, r, x);
      |                          ~~~~~^~
happiness.cpp:35:35: note:   initializing argument 3 of 'void update(int&, ll&, ll&, ll&, ll&, ll&)'
   35 | void update(int &node, ll &s, ll &e, ll &l, ll &r, ll &x) {
      |                               ~~~~^
happiness.cpp:54:30: error: cannot bind non-const lvalue reference of type 'll&' {aka 'long long int&'} to an rvalue of type 'll' {aka 'long long int'}
   54 |  update(tree[node].r, (s+e)/2+1, e, l, r, x);
      |                       ~~~~~~~^~
happiness.cpp:35:28: note:   initializing argument 2 of 'void update(int&, ll&, ll&, ll&, ll&, ll&)'
   35 | void update(int &node, ll &s, ll &e, ll &l, ll &r, ll &x) {
      |                        ~~~~^
happiness.cpp: In function 'bool init(int, long long int, long long int*)':
happiness.cpp:67:46: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   67 |   if(chk.find(coins[i]) == chk.end()) update(0, 0, m, coins[i], coins[i], -INF);
      |                                              ^
happiness.cpp:35:18: note:   initializing argument 1 of 'void update(int&, ll&, ll&, ll&, ll&, ll&)'
   35 | void update(int &node, ll &s, ll &e, ll &l, ll &r, ll &x) {
      |             ~~~~~^~~~
happiness.cpp:69:10: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   69 |   update(0, 0, m, coins[i]+1, m, coins[i]);
      |          ^
happiness.cpp:35:18: note:   initializing argument 1 of 'void update(int&, ll&, ll&, ll&, ll&, ll&)'
   35 | void update(int &node, ll &s, ll &e, ll &l, ll &r, ll &x) {
      |             ~~~~~^~~~
happiness.cpp: In function 'bool is_happy(int, int, long long int*)':
happiness.cpp:81:83: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   81 |   if(chk.find(coins[i]) != chk.end() && chk[coins[i]] == 1 && event == -1) update(0, 0, m, coins[i], coins[i], INF);
      |                                                                                   ^
happiness.cpp:35:18: note:   initializing argument 1 of 'void update(int&, ll&, ll&, ll&, ll&, ll&)'
   35 | void update(int &node, ll &s, ll &e, ll &l, ll &r, ll &x) {
      |             ~~~~~^~~~
happiness.cpp:82:84: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   82 |   if((chk.find(coins[i]) == chk.end() || chk[coins[i]] == 0) && event == 1) update(0, 0, m, coins[i], coins[i], -INF);
      |                                                                                    ^
happiness.cpp:35:18: note:   initializing argument 1 of 'void update(int&, ll&, ll&, ll&, ll&, ll&)'
   35 | void update(int &node, ll &s, ll &e, ll &l, ll &r, ll &x) {
      |             ~~~~~^~~~
happiness.cpp:84:25: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   84 |   if(event == 1) update(0, 0, m, coins[i]+1, m, coins[i]);
      |                         ^
happiness.cpp:35:18: note:   initializing argument 1 of 'void update(int&, ll&, ll&, ll&, ll&, ll&)'
   35 | void update(int &node, ll &s, ll &e, ll &l, ll &r, ll &x) {
      |             ~~~~~^~~~
happiness.cpp:85:15: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   85 |   else update(0, 0, m, coins[i]+1, m, -coins[i]);
      |               ^
happiness.cpp:35:18: note:   initializing argument 1 of 'void update(int&, ll&, ll&, ll&, ll&, ll&)'
   35 | void update(int &node, ll &s, ll &e, ll &l, ll &r, ll &x) {
      |             ~~~~~^~~~
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
   16 |  long long max_code;
      |            ^~~~~~~~