# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
275721 |
2020-08-20T07:19:02 Z |
반딧불(#5115) |
Happiness (Balkan15_HAPPINESS) |
C++17 |
|
2000 ms |
264052 KB |
#include <unordered_set>
#include <climits>
#include <vector>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#include "happiness.h"
using namespace std;
typedef long long ll;
unordered_set<ll> st;
struct Node{
ll s, e;
ll sum = 0;
int l=0, r=0;
Node(){}
Node(ll s, ll e): s(s), e(e){}
};
vector<Node> vec;
inline ll minSum(int i, ll idx){ /// returning sum
ll s = vec[i].s, e = vec[i].e;
int l = vec[i].l, r = vec[i].r;
if(idx <= s) return 0;
if(e < idx) return vec[i].sum;
ll ret = 0;
if(l && vec[l].sum) ret += minSum(l, idx);
if(r && vec[r].sum) ret += minSum(r, idx);
return ret;
}
inline ll minMax(int i, ll idx){ /// returning value
ll s = vec[i].s, e = vec[i].e;
int l = vec[i].l, r = vec[i].r;
if(idx <= s) return 0;
if(s==e) return s;
ll m = (s+e)>>1;
if(idx <= m+1){
if(l && vec[l].sum) return minMax(l, idx);
return 0;
}
if(r && vec[r].sum){
ll tmp = minMax(r, idx);
if(tmp) return tmp;
}
if(l && vec[l].sum){
ll tmp = minMax(l, idx);
if(tmp) return tmp;
}
return 0;
}
inline ll maxMin(int i, ll idx){ /// returning value
ll s = vec[i].s, e = vec[i].e;
int l = vec[i].l, r = vec[i].r;
if(e <= idx) return LLONG_MAX;
if(s==e) return s;
ll m = (s+e)>>1;
if(m <= idx){
if(r && vec[r].sum) return maxMin(r, idx);
return LLONG_MAX;
}
if(l && vec[l].sum){
ll tmp = maxMin(l, idx);
if(tmp != LLONG_MAX) return tmp;
}
if(r && vec[r].sum){
ll tmp = maxMin(r, idx);
if(tmp != LLONG_MAX) return tmp;
}
return LLONG_MAX;
}
void addValue(int i, ll idx, ll val){
ll s = vec[i].s, e = vec[i].e;
int l = vec[i].l, r = vec[i].r;
if(s==e){
vec[i].sum += val;
ll lv = minMax(0, idx);
ll rv = maxMin(0, idx);
if(vec[i].sum){ /// adding
if(lv*2 < idx) st.insert(idx);
else st.erase(idx);
if(rv != LLONG_MAX){
if(idx*2 < rv) st.insert(rv);
else st.erase(rv);
}
}
else{ /// deleted
st.erase(idx);
if(rv != LLONG_MAX){
if(lv*2 < rv) st.insert(rv);
else st.erase(rv);
}
}
return;
}
ll m = (s+e)>>1;
if(idx <= m){
if(!l) vec[i].l = l = (int)vec.size(), vec.push_back(Node(s, m));
addValue(l, idx, val);
}
else{
if(!r) vec[i].r = r = (int)vec.size(), vec.push_back(Node(m+1, e));
addValue(r, idx, val);
}
vec[i].sum = (!l ? 0 : vec[l].sum) + (!r ? 0 : vec[r].sum);
}
int n, cnt;
bool isAble(){
for(auto &x: st){
// printf("strange(%lld) ", x);
if(minSum(0, x) + 1 < x) return false;
}
return true;
}
bool init(int coinsCount, ll maxCoinSize, ll coins[]) {
n = coinsCount;
vec.push_back(Node(1, maxCoinSize));
for(int i=0; i<n; i++){
addValue(0, coins[i], coins[i]);
}
return isAble();
}
bool is_happy(int event, int coinsCount, ll coins[]) {
n += coinsCount * event;
for(int i=0; i<coinsCount; i++) addValue(0, 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;
| ^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
1528 KB |
Output is correct |
7 |
Correct |
7 ms |
2548 KB |
Output is correct |
8 |
Correct |
68 ms |
16932 KB |
Output is correct |
9 |
Correct |
66 ms |
16976 KB |
Output is correct |
10 |
Correct |
59 ms |
16984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
950 ms |
34200 KB |
Output is correct |
7 |
Correct |
813 ms |
34200 KB |
Output is correct |
8 |
Correct |
806 ms |
34336 KB |
Output is correct |
9 |
Correct |
1409 ms |
34116 KB |
Output is correct |
10 |
Correct |
1152 ms |
34124 KB |
Output is correct |
11 |
Correct |
427 ms |
33468 KB |
Output is correct |
12 |
Correct |
527 ms |
33468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
1528 KB |
Output is correct |
7 |
Correct |
7 ms |
2548 KB |
Output is correct |
8 |
Correct |
68 ms |
16932 KB |
Output is correct |
9 |
Correct |
66 ms |
16976 KB |
Output is correct |
10 |
Correct |
59 ms |
16984 KB |
Output is correct |
11 |
Correct |
950 ms |
34200 KB |
Output is correct |
12 |
Correct |
813 ms |
34200 KB |
Output is correct |
13 |
Correct |
806 ms |
34336 KB |
Output is correct |
14 |
Correct |
1409 ms |
34116 KB |
Output is correct |
15 |
Correct |
1152 ms |
34124 KB |
Output is correct |
16 |
Correct |
427 ms |
33468 KB |
Output is correct |
17 |
Correct |
527 ms |
33468 KB |
Output is correct |
18 |
Execution timed out |
2079 ms |
264052 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |