#include "happiness.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define fi first
#define se second
int index = 0; ll mx;
vector<ll> segTree;
vector<pair<int,int>> child;
void add_node(ll v=0,int le=-1,int ri=-1){
segTree.pb(v), child.pb({le,ri});
}
void update(ll i, int v, int p=0, ll l=1, ll r=mx){
if(l==r) { segTree[p]+=v; return; }
ll mid = (l+r)/2;
if(i<=mid){
if(child[p].fi==-1) child[p].fi=++index, add_node();
update(i,v,child[p].fi,l,mid);
}
else{
if(child[p].se==-1) child[p].se=++index, add_node();
update(i,v,child[p].se,mid+1,r);
}
segTree[p] = segTree[child[p].fi]+segTree[child[p].se];
}
ll query(ll i, ll j, int p=0, ll l=1, ll r=mx){
if(i>r or j<l or i>j or p==-1) return 0ll;
if(i<=l and r<=j) return segTree[p];
ll mid = (l+r)/2;
return query(i,j,child[p].fi,l,mid)+query(i,j,child[p].se,mid+1,r);
}
bool chk(){
ll coin = 1;
while(1){
int sum = query(1,coin);
if(sum+1>mx) return true;
if(query(1,mx)==sum) return true;
if(query(1,sum+1)==sum) return false;
coin = sum+1;
}
}
bool init(int n, ll M, ll a[]) {
mx = M; add_node();
for(int i = 0; i < n; i++) update(a[i],a[i]);
return chk();
}
bool is_happy(int e, int n, ll a[]) {
for(int i = 0; i < n; i++) update(a[i],a[i]*e);
return chk();
}
Compilation message
happiness.cpp:8:5: error: 'int index' redeclared as different kind of entity
8 | int index = 0; ll mx;
| ^~~~~
In file included from /usr/include/string.h:432,
from /usr/include/c++/10/cstring:42,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:48,
from happiness.cpp:2:
/usr/include/strings.h:61:1: note: previous declaration 'const char* index(const char*, int)'
61 | index (const char *__s, int __c) __THROW
| ^~~~~
happiness.cpp: In function 'void update(ll, int, int, ll, ll)':
happiness.cpp:20:43: error: no pre-increment operator for type
20 | if(child[p].fi==-1) child[p].fi=++index, add_node();
| ^~~~~
happiness.cpp:24:43: error: no pre-increment operator for type
24 | if(child[p].se==-1) child[p].se=++index, add_node();
| ^~~~~
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
16 | long long max_code;
| ^~~~~~~~