| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 775366 | VMaksimoski008 | Happiness (Balkan15_HAPPINESS) | C++14 | 274 ms | 34296 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "happiness.h"
using ll = long long;
struct Node {
ll sum = 0;
Node *lc, *rc;
ll l, r;
Node(ll l, ll r) : l(l), r(r), lc(nullptr), rc(nullptr) {}
void update(int pos, int val) {
sum += val;
if(l == r) return;
auto tm = (l + r) / 2;
if(pos <= tm) {
if(lc == nullptr) lc = new Node(l, tm);
lc->update(pos, val);
} else {
if(rc == nullptr) rc = new Node(tm+1, r);
rc->update(pos, val);
}
}
ll query(int tl, int tr) {
if(tl > r || l > tr) return 0;
if(r <= tr && l >= tl) return this->sum;
ll res = 0;
if(lc) res += lc->query(tl, tr);
if(rc) res += rc->query(tl, tr);
return res;
}
};
Node *root;
bool check() {
ll curr = 1;
ll sum = root->sum;
while(sum > curr) {
ll res = root->query(1, curr);
if(res < curr) return 0;
curr = res + 1;
}
return 1;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
root = new Node(1, maxCoinSize);
for(int i=0; i<coinsCount; i++)
root->update(coins[i], coins[i]);
return check();
}
bool is_happy(int event, int coinsCount, long long coins[]) {
for(int i=0; i<coinsCount; i++) {
if(event == -1) root->update(coins[i], 0 - coins[i]);
else root->update(coins[i], coins[i]);
}
return check();
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
