답안 #925149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925149 2024-02-10T21:20:16 Z myst6 Happiness (Balkan15_HAPPINESS) C++14
0 / 100
176 ms 524288 KB
#include "happiness.h"
#include <bits/stdc++.h>
#pragma GCC diagnostic error "-std=c++11"
#pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3)
#pragma GCC target("avx","sse2")

using namespace std;
using ll = long long;

struct Node;

const int sz = 23'000'000;
int nextfree = 1;
vector<Node> nodes(sz);

struct Node {
	ll tag, mx;
	int left, right;
	Node() : tag(0), mx(0), left(0), right(0) {}
	void extend(ll xl, ll xr) {
		if (xl != xr && !left) {
			left = nextfree++;
			right = nextfree++;
		}
	}
	void apply(ll xl, ll xr) {
		extend(xl, xr);
		if (tag != 0) {
			mx += tag;
			if (left) nodes[left].tag += tag;
			if (right) nodes[right].tag += tag;
			tag = 0;
		}
	}
	void update(ll l, ll r, ll xl, ll xr, ll delta) {
		if (l > r) return;
		if (l == xl && r == xr) {
			tag += delta;
		} else {
			apply(xl, xr);
			ll xm = (xl + xr) / 2;
			nodes[left].update(l, min(r, xm), xl, xm, delta);
			nodes[right].update(max(l, xm+1), r, xm+1, xr, delta);
			nodes[left].apply(xl, xm); nodes[right].apply(xm+1, xr);
			mx = max(nodes[left].mx, nodes[right].mx);
		}
	}
} tree;

ll hi = 1'000'000'000'005LL;

unordered_map<ll,int> cnt;

void add(ll coin) {
	cnt[coin] += 1;
	if (cnt[coin] == 1) tree.update(coin, coin, 1, hi, +coin);
	tree.update(coin+1, hi, 1, hi, -coin);
}

void remove(ll coin) {
	cnt[coin] -= 1;
	if (cnt[coin] == 0) tree.update(coin, coin, 1, hi, -coin);
	tree.update(coin+1, hi, 1, hi, +coin);
}

bool check() {
	tree.apply(1, hi);
	return tree.mx <= 1;
}

bool init(int coinsCount, ll maxCoinSize, ll coins[]) {
	hi = maxCoinSize+1;
	cnt.reserve(700'000);
	for (int i=0; i<coinsCount; i++) add(coins[i]);
	return check();
}

bool is_happy(int event, int coinsCount, ll coins[]) {
	for (int i=0; i<coinsCount; i++) 
		if (event == 1) add(coins[i]);
		else remove(coins[i]);
	return check();
}

Compilation message

happiness.cpp:3:30: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    3 | #pragma GCC diagnostic error "-std=c++11"
      |                              ^~~~~~~~~~~~
happiness.cpp:4:802: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
    4 | #pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3)
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  ^
happiness.cpp:4:802: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
happiness.cpp:4:802: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
happiness.cpp:4:802: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
    5 | #pragma GCC target("avx","sse2")
      |                                ^
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
happiness.cpp:5:32: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
happiness.cp
# 결과 실행 시간 메모리 Grader output
1 Runtime error 176 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 176 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 176 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 176 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -