#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include "happiness.h"
using namespace std;
typedef long long ll;
const ll INF = 1e18;
struct Node{
ll s, e;
ll sum = 0;
ll v = INF, lazy = 0;
Node *l=nullptr, *r=nullptr, *root=nullptr;
Node(){}
Node(ll s, ll e, Node *root): s(s), e(e), root(root){}
~Node(){
if(l) delete l;
if(r) delete r;
}
void propagate(){
if(l) l->lazy += lazy;
if(r) r->lazy += lazy;
v += lazy;
lazy = 0;
}
ll minSum(ll idx){ /// returning sum
if(idx <= s) return 0;
if(e < idx) return sum;
ll ret = 0;
if(l) ret += l->minSum(idx);
if(r) ret += r->minSum(idx);
return ret;
}
void addKey(ll _s, ll _e, ll val){
propagate();
if(e < _s || s > _e) return;
if(_s <= s && e <= _e){
lazy += val;
propagate();
return;
}
if(l) l->addKey(_s, _e, val);
if(r) r->addKey(_s, _e, val);
v = min(l?l->v:INF, r?r->v:INF);
}
void addValue(ll idx, ll val){
propagate();
if(s==e){
sum += val;
root->addKey(idx+1, INF, val);
if(v == INF) v = root->minSum(idx) - idx;
return;
}
ll m = (s+e)/2;
if(idx <= m){
if(!l) l = new Node(s, m, root);
l->addValue(idx, val);
if(!l->sum) delete l, l=nullptr;
}
else{
if(!r) r = new Node(m+1, e, root);
r->addValue(idx, val);
if(!r->sum) delete r, r=nullptr;
}
if(l) l->propagate();
if(r) r->propagate();
sum = (!l ? 0 : l->sum) + (!r ? 0 : r->sum);
v = min(!l ? INF: l->v, !r ? INF : r->v);
}
};
Node* root;
bool isAble(){
root->propagate();
if(root->v >= -1) return true;
return false;
}
bool init(int coinsCount, ll maxCoinSize, ll coins[]) {
root = new Node();
root->s= 1, root->e = maxCoinSize;
root->root = root;
for(int i=0; i<coinsCount; i++){
root->addValue(coins[i], coins[i]);
}
return isAble();
}
bool is_happy(int event, int coinsCount, ll coins[]){
for(int i=0; i<coinsCount; i++) root->addValue(coins[i], coins[i] * event);
return isAble();
}
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 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
2816 KB |
Output is correct |
7 |
Correct |
8 ms |
2816 KB |
Output is correct |
8 |
Correct |
66 ms |
22108 KB |
Output is correct |
9 |
Correct |
73 ms |
22136 KB |
Output is correct |
10 |
Correct |
59 ms |
22136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
975 ms |
36348 KB |
Output is correct |
7 |
Correct |
978 ms |
36472 KB |
Output is correct |
8 |
Correct |
1004 ms |
36600 KB |
Output is correct |
9 |
Correct |
1864 ms |
36620 KB |
Output is correct |
10 |
Correct |
1683 ms |
48376 KB |
Output is correct |
11 |
Correct |
670 ms |
43620 KB |
Output is correct |
12 |
Correct |
628 ms |
43564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
2816 KB |
Output is correct |
7 |
Correct |
8 ms |
2816 KB |
Output is correct |
8 |
Correct |
66 ms |
22108 KB |
Output is correct |
9 |
Correct |
73 ms |
22136 KB |
Output is correct |
10 |
Correct |
59 ms |
22136 KB |
Output is correct |
11 |
Correct |
975 ms |
36348 KB |
Output is correct |
12 |
Correct |
978 ms |
36472 KB |
Output is correct |
13 |
Correct |
1004 ms |
36600 KB |
Output is correct |
14 |
Correct |
1864 ms |
36620 KB |
Output is correct |
15 |
Correct |
1683 ms |
48376 KB |
Output is correct |
16 |
Correct |
670 ms |
43620 KB |
Output is correct |
17 |
Correct |
628 ms |
43564 KB |
Output is correct |
18 |
Execution timed out |
2012 ms |
192336 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |