답안 #568967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568967 2022-05-26T11:47:36 Z Dan4Life Happiness (Balkan15_HAPPINESS) C++17
0 / 100
0 ms 212 KB
#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 IND = 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, ll 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=++IND, add_node();
        update(i,v,child[p].fi,l,mid);
    }
    else{
        if(child[p].se==-1) child[p].se=++IND, 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;
    ll le = child[p].fi==-1?0ll:query(i,j,child[p].fi,l,mid);
    ll ri = child[p].se==-1?0ll:query(i,j,child[p].se,mid+1,r);
    return le+ri;
}

bool chk(){
    ll coin = 1;
    while(1){
        int sum = query(1,coin);
        if(sum+1>mx) return true;
        if(query(1,sum+1)==sum) return false;
        coin = sum+1;
    }
    return true;
}

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

grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
   16 |  long long max_code;
      |            ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -