結果

問題 No.3327 うるせぇ、ポリオミノぶつけんぞ
コンテスト
ユーザー pengin_2000
提出日時 2025-11-01 15:41:12
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 261 ms / 3,000 ms
コード長 1,200 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 28,076 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-01 15:41:21
合計ジャッジ時間 6,878 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:34:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |         scanf("%d %d", &n, &q);
      |         ^~~~~~~~~~~~~~~~~~~~~~
main.c:37:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |                 scanf("%d", &a[i]);
      |                 ^~~~~~~~~~~~~~~~~~
main.c:47:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |                 scanf("%d %d", &c, &x);
      |                 ^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
int max(int a, int b)
{
	if (a > b)
		return a;
	else
		return b;
}
int seg[800005], ss;
void update(int x, int v)
{
	x += ss - 1;
	seg[x] = v;
	while (x > 0)
	{
		x = (x - 1) / 2;
		seg[x] = max(seg[2 * x + 1], seg[2 * x + 2]);
	}
	return;
}
int get_max(int l, int r)
{
	int res = -1;
	l += ss - 1;
	r += ss - 1;
	for (; l <= r; l /= 2, r = r / 2 - 1)
		res = max(res, max(seg[l], seg[r]));
	return res;
}
int a[200005];
int main()
{
	int n, q;
	scanf("%d %d", &n, &q);
	int i;
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (ss = 1; ss < n; ss *= 2);
	for (i = 0; i < 2 * ss - 1; i++)
		seg[i] = -1;
	for (i = 0; i < n; i++)
		update(i, a[i]);
	int c, x;
	int l, m, r;
	for (; q > 0; q--)
	{
		scanf("%d %d", &c, &x);
		if (get_max(0, n - 1) <= x)
		{
			printf("-1\n");
			continue;
		}
		l = -1;
		r = n;
		if (c == 1)
		{
			while (r - l > 1)
			{
				m = (l + r) / 2;
				if (get_max(0, m) > x)
					r = m;
				else
					l = m;
			}
			printf("%d\n", r + 1);
			update(r, -1);
		}
		else
		{
			while (r - l > 1)
			{
				m = (l + r) / 2;
				if (get_max(m, n - 1) > x)
					l = m;
				else
					r = m;
			}
			printf("%d\n", l + 1);
			update(l, -1);
		}
	}
	return 0;
}
0