結果

問題 No.1679 マスゲーム
ユーザー pengin_2000pengin_2000
提出日時 2022-10-13 22:51:35
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,946 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 29,732 KB
実行使用メモリ 9,756 KB
最終ジャッジ日時 2023-09-08 19:16:49
合計ジャッジ時間 2,890 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,000 KB
testcase_01 AC 2 ms
7,936 KB
testcase_02 AC 2 ms
7,976 KB
testcase_03 AC 96 ms
9,536 KB
testcase_04 AC 96 ms
9,544 KB
testcase_05 AC 96 ms
9,600 KB
testcase_06 AC 96 ms
9,732 KB
testcase_07 AC 96 ms
9,736 KB
testcase_08 AC 96 ms
9,740 KB
testcase_09 AC 96 ms
9,732 KB
testcase_10 AC 96 ms
9,672 KB
testcase_11 AC 96 ms
9,684 KB
testcase_12 AC 9 ms
8,008 KB
testcase_13 AC 38 ms
8,504 KB
testcase_14 AC 95 ms
9,732 KB
testcase_15 AC 82 ms
9,312 KB
testcase_16 AC 70 ms
9,328 KB
testcase_17 AC 2 ms
7,912 KB
testcase_18 AC 75 ms
9,756 KB
testcase_19 AC 2 ms
7,976 KB
testcase_20 AC 2 ms
8,068 KB
testcase_21 AC 2 ms
7,944 KB
testcase_22 AC 2 ms
7,880 KB
testcase_23 AC 2 ms
7,976 KB
testcase_24 AC 2 ms
7,884 KB
testcase_25 AC 2 ms
8,068 KB
testcase_26 AC 2 ms
8,068 KB
testcase_27 AC 2 ms
7,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int h[200005], l;
int comp_h(long long int a, long long int b)
{
	if (h[a] > h[b])
		return 1;
	else
		return -1;
}
void swap_h(long long int a, long long int b)
{
	long long int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void push(long long int ne)
{
	h[l] = ne;
	long long int p = l;
	l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
long long int pop()
{
	l--;
	swap_h(0, l);
	long long int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
long long int a[200005], b[200005], t[200005];
long long int x[200005], y[200005], xx, yy;
long long int fined_left(long long int Y)
{
	long long int min, mid, max;
	min = -1;
	max = yy;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (y[mid] < Y)
			min = mid;
		else
			max = mid;
	}
	return min;
}
long long int fined_right(long long int Y)
{
	long long int min, mid, max;
	min = -1;
	max = yy;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (y[mid] <= Y)
			min = mid;
		else
			max = mid;
	}
	return min;
}
int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int i;
	for (i = 0; i < n; i++)
		scanf("%lld %lld %lld", &a[i], &b[i], &t[i]);
	l = 0;
	for (i = 0; i < n; i++)
		if (a[i] == 0)
			push(b[i] - t[i]);
	for (xx = 0; l > 0; xx++)
		x[xx] = pop();
	l = 0;
	for (i = 0; i < n; i++)
		if (a[i] == 1)
			push(b[i] - t[i]);
	for (yy = 0; l > 0; yy++)
		y[yy] = pop();
	long long int ans = 0;
	for (i = 0; i < xx; i++)
		ans += fined_right(x[i]) - fined_left(x[i]);
	printf("%lld\n", ans);
	return 0;
}
0