이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#include "happiness.h"
#include <bits/stdc++.h>
using namespace std;
struct Node {
    // sum that is required such that the first element of the subarray is chosen
    long long reqSum = 0;
    // sum of all elements in the subarray
    long long buildSum = 0;
    // index of left and right children
    int lIdx = -1, rIdx = -1;
};
struct Segtree {
    const long long n=((long long)1LL)<<40;
    Node n1;
    vector<Node> seg;
    int pt=0;
    void init() {
        seg.assign((int)1e7 + 2*(int)1e6,n1);
    }
    void combine(Node &ret, Node &l, Node &r) {        
		ret.buildSum = l.buildSum + r.buildSum;
		ret.reqSum = l.reqSum;
		if (r.buildSum != 0)
        	ret.reqSum = max(l.reqSum, r.reqSum - l.buildSum);
    }
    void gen(int x, bool two, long long f) {
        if (seg[x].lIdx != -1) return;
        seg[x].lIdx = ++pt;
        if (two) {
            seg[pt].reqSum = f-1;
        }
        seg[x].rIdx = ++pt;
        if (two) {
            seg[pt].reqSum = f;
        }
    }
    void inc(long long i, long long v, int x, long long lx, long long rx) {
        if (rx-lx==1) {
            seg[x].buildSum += v;
            return;
        }
        gen(x, rx-lx==2,lx);
        long long m=(lx+rx)>>1;
        if (i<m)inc(i,v,seg[x].lIdx,lx,m);
        else inc(i,v,seg[x].rIdx,m,rx);
        combine(seg[x], seg[seg[x].lIdx], seg[seg[x].rIdx]);
    }
    void add(long long i) {
        inc(i, i, 0, 0, n);
    }
    void sub(long long i) {
        inc(i, -i, 0, 0, n);
    }
    bool happy() {
        return seg[0].reqSum <= 0;
    }
};
Segtree sg;
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
    sg.init();
    for (int i=0;i<coinsCount;i++) {
        sg.add(coins[i]);
    }
    return sg.happy();
}
bool is_happy(int event, int32_t coinsCount, long long coins[]) {
    if (event == -1) {
        for (int i=0;i<coinsCount;i++) {
            sg.sub(coins[i]);
        }
    }
    else {
        for (int i=0;i<coinsCount;i++) {
            sg.add(coins[i]);
        }
    }
    
    return sg.happy();
}
컴파일 시 표준 에러 (stderr) 메시지
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
   16 |  long long max_code;
      |            ^~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |