結果

問題 No.1439 Let's Compare!!!!
ユーザー pengin_2000pengin_2000
提出日時 2022-10-02 17:04:46
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 29,040 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 15:03:50
合計ジャッジ時間 2,314 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 87 ms
4,376 KB
testcase_11 AC 69 ms
4,376 KB
testcase_12 AC 69 ms
4,376 KB
testcase_13 AC 89 ms
4,376 KB
testcase_14 AC 88 ms
4,376 KB
testcase_15 AC 73 ms
4,380 KB
testcase_16 AC 75 ms
4,376 KB
testcase_17 AC 86 ms
4,380 KB
testcase_18 AC 43 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
int h[400005], l;
int comp_h(int a, int b)
{
	if (h[a] > h[b])
		return 1;
	else
		return -1;
}
void swap_h(int a, int b)
{
	int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void push(int ne)
{
	h[l] = ne;
	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;
}
int pop()
{
	l--;
	swap_h(0, l);
	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];
}
char s[200005], t[200005];
int main()
{
	int n;
	scanf("%d", &n);
	scanf("%s%s", s, t);
	int q;
	scanf("%d", &q);
	char c[4];
	int x, y;
	int i, j, k;
	l = 0;
	for (i = 0; i < n; i++)
	{
		if (s[i] != t[i])
			push(i);
	}
	for (i = 0; i < q; i++)
	{
		scanf("%s %d %d", &c, &x, &y);
		x--;
		if (c[0] == 'S')
			s[x] = '0' + y;
		else
			t[x] = '0' + y;
		if (s[x] != t[x])
			push(x);
		k = -1;
		while (l > 0)
		{
			j = pop();
			if (s[j] != t[j])
			{
				k = j;
				push(j);
				break;
			}
		}
		if (k < 0)
			printf("=\n");
		else if (s[k] < t[k])
			printf("<\n");
		else
			printf(">\n");
	}
	return 0;
}
0