답안 #275365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
275365 2020-08-20T05:42:52 Z 송준혁(#5101) Happiness (Balkan15_HAPPINESS) C++17
60 / 100
2000 ms 295076 KB
#include "happiness.h"
#include <bits/stdc++.h>
#define INF (1ll<<61)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

LL M;
int num=1, lc[30303030], rc[30303030];
LL T[30303030], lz[30303030];
multiset<LL> S;

void busy(int id){
	if (!lz[id]) return;
	if (!lc[id]) lc[id]=++num, T[num]=INF;
	if (!rc[id]) rc[id]=++num, T[num]=INF;
	T[lc[id]] += lz[id], lz[lc[id]] += lz[id];
	T[rc[id]] += lz[id], lz[rc[id]] += lz[id];
	lz[id] = 0;
}

void upd(int id, LL s, LL e, LL ts, LL te, LL v){
	if (e < ts || te < s) return;
	if (ts <= s && e <= te){
		T[id] += v, lz[id] += v;
		return;
	}
	busy(id);
	LL m=s+e>>1;
	if (!lc[id] && ts <= m) lc[id]=++num, T[num]=INF;
	if (!rc[id] && te > m) rc[id]=++num, T[num]=INF;
	upd(lc[id], s, m, ts, te, v);
	upd(rc[id], m+1, e, ts, te, v);
	T[id] = min(T[lc[id]], T[rc[id]]);
}

bool init(int N, long long _M, long long A[]) {
	M = _M;
	T[0]=T[1]=INF;
	for (int i=0; i<N; i++){
		upd(1, 1, M, A[i]+1, M, A[i]);
		if (S.find(A[i]) == S.end()) upd(1, 1, M, A[i], A[i], -INF-A[i]);
		S.insert(A[i]);
	}
	return T[1]>=-1;
}

bool is_happy(int e, int N, long long A[]) {
	if (e>0){
		for (int i=0; i<N; i++){
			upd(1, 1, M, A[i]+1, M, A[i]);
			if (S.find(A[i]) == S.end()) upd(1, 1, M, A[i], A[i], -INF-A[i]);
			S.insert(A[i]);
		}
	}
	else{
		for (int i=0; i<N; i++){
			upd(1, 1, M, A[i]+1, M, -A[i]);
			S.erase(S.find(A[i]));
			if (S.find(A[i]) == S.end()) upd(1, 1, M, A[i], A[i], INF+A[i]);
		}
	}
	return T[1]>=-1;
}

Compilation message

happiness.cpp: In function 'void upd(int, LL, LL, LL, LL, LL)':
happiness.cpp:29:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |  LL m=s+e>>1;
      |       ~^~
grader.cpp: In function 'int main()':
grader.cpp:14:9: warning: unused variable 'd' [-Wunused-variable]
   14 |  int i, d;
      |         ^
grader.cpp:15:12: warning: unused variable 'max_code' [-Wunused-variable]
   15 |  long long max_code;
      |            ^~~~~~~~
grader.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  scanf("%d%lld", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
grader.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |   scanf("%lld", &coins[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
grader.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
grader.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |   scanf("%d%d", &ck, &c);
      |   ~~~~~^~~~~~~~~~~~~~~~~
grader.cpp:28:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |    scanf("%lld", &A[j]);
      |    ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 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 384 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 5 ms 1920 KB Output is correct
7 Correct 7 ms 2048 KB Output is correct
8 Correct 52 ms 13944 KB Output is correct
9 Correct 56 ms 14148 KB Output is correct
10 Correct 50 ms 13560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 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 1002 ms 30676 KB Output is correct
7 Correct 948 ms 30456 KB Output is correct
8 Correct 1022 ms 30840 KB Output is correct
9 Correct 1607 ms 36536 KB Output is correct
10 Correct 1939 ms 41296 KB Output is correct
11 Correct 654 ms 26396 KB Output is correct
12 Correct 619 ms 26360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 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 5 ms 1920 KB Output is correct
7 Correct 7 ms 2048 KB Output is correct
8 Correct 52 ms 13944 KB Output is correct
9 Correct 56 ms 14148 KB Output is correct
10 Correct 50 ms 13560 KB Output is correct
11 Correct 1002 ms 30676 KB Output is correct
12 Correct 948 ms 30456 KB Output is correct
13 Correct 1022 ms 30840 KB Output is correct
14 Correct 1607 ms 36536 KB Output is correct
15 Correct 1939 ms 41296 KB Output is correct
16 Correct 654 ms 26396 KB Output is correct
17 Correct 619 ms 26360 KB Output is correct
18 Correct 1916 ms 215700 KB Output is correct
19 Correct 1767 ms 224136 KB Output is correct
20 Execution timed out 2090 ms 295076 KB Time limit exceeded
21 Halted 0 ms 0 KB -