Submission #512815

# Submission time Handle Problem Language Result Execution time Memory
512815 2022-01-16T18:04:43 Z Eyed Happiness (Balkan15_HAPPINESS) C++17
60 / 100
1834 ms 524292 KB
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll MOD = 1e9 + 7;

map<ll, ll> numHas;

struct node {
	ll lN;
	ll rN;
	ll a; //max over range
	bool mark;
	ll lazy; //need to add each element in v2	
	node(ll l = -1, ll r = -1, ll b = 0) : lN(l), rN(r), a(b), mark(false), lazy(0) {};
};

vector<node> st;
void makeChild(ll v) {
	if (st[v].lN == -1) {
		st[v].lN = st.size();
		st.push_back(node(-1, -1, 0));
	}
	if (st[v].rN == -1) {
		st[v].rN = st.size();
		st.push_back(node(-1, -1, 0));
	}
}
void push(ll v) {
	if (st[v].mark) {
		st[v].mark = false;
		makeChild(v);
		st[st[v].lN].mark = true;
		st[st[v].rN].mark = true;
		st[st[v].lN].lazy += st[v].lazy;
		st[st[v].rN].lazy += st[v].lazy;
		st[st[v].lN].a += st[v].lazy;
		st[st[v].rN].a += st[v].lazy;
		st[v].lazy = 0;
	}
}
void upd(ll v, ll tl, ll tr, ll x, ll l, ll r) {
	//upd adds x from l to r
	if (l > r) return;
	if (l <= tl && r >= tr) {
		st[v].a += x;
		st[v].lazy += x;
		st[v].mark = true;
		return;
	}
	push(v);
	makeChild(v);
	ll mid = (tl + tr) / 2;
	upd(st[v].lN, tl, mid, x, max(l, tl), min(r, mid));
	upd(st[v].rN, mid + 1, tr, x, max(l, mid + 1), min(r, tr));
	st[v].a = max(st[st[v].lN].a, st[st[v].rN].a);
}
void update(ll x, ll e) {
	if (numHas.find(x) != numHas.end()) numHas[x]+=e;
	else numHas[x] = e;
	upd(0, 0, 1e12, -e * x, x + 1, 1e12);
	if (e == 1 && numHas[x] == 1) {
		upd(0, 0, 1e12, x, x, x);
	}
	if (e == -1 && numHas[x] == 0) {
		upd(0, 0, 1e12, -x, x, x);
	}
}
bool qry() { return st[0].a <= 1; }
void init() { st.push_back(node()); }

bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
	init();
	for (ll i = 0; i < coinsCount; ++i) update(coins[i], 1);
	return qry();
}

bool is_happy(int event, int coinsCount, long long coins[]) {
	for (ll i = 0; i < coinsCount; ++i) update(coins[i], event);
	return qry();
}


//ll main() {
//	ios::sync_with_stdio(0);
//	cin.tie(0);
//
//	long long arr[5] = { 1,2,4,8,16 };
//	cout << init(5, 100, arr) << endl;
//	ll a1[2] = { 2,8 };
//	cout << is_happy(-1, 2, a1) << endl;
//	ll a2[3] = { 7,9,2 };
//	cout << is_happy(1, 3, a2) << endl;
//
//	return 0;
//}

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 1 ms 304 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 5 ms 2976 KB Output is correct
7 Correct 7 ms 5536 KB Output is correct
8 Correct 70 ms 42152 KB Output is correct
9 Correct 68 ms 42168 KB Output is correct
10 Correct 64 ms 42108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1141 ms 97648 KB Output is correct
7 Correct 1171 ms 56196 KB Output is correct
8 Correct 1162 ms 97872 KB Output is correct
9 Correct 1834 ms 97564 KB Output is correct
10 Correct 1830 ms 96704 KB Output is correct
11 Correct 902 ms 60676 KB Output is correct
12 Correct 977 ms 60908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 5 ms 2976 KB Output is correct
7 Correct 7 ms 5536 KB Output is correct
8 Correct 70 ms 42152 KB Output is correct
9 Correct 68 ms 42168 KB Output is correct
10 Correct 64 ms 42108 KB Output is correct
11 Correct 1141 ms 97648 KB Output is correct
12 Correct 1171 ms 56196 KB Output is correct
13 Correct 1162 ms 97872 KB Output is correct
14 Correct 1834 ms 97564 KB Output is correct
15 Correct 1830 ms 96704 KB Output is correct
16 Correct 902 ms 60676 KB Output is correct
17 Correct 977 ms 60908 KB Output is correct
18 Runtime error 1623 ms 524292 KB Execution killed with signal 9
19 Halted 0 ms 0 KB -