結果

問題 No.3198 Monotonic Query
ユーザー pengin_2000
提出日時 2025-07-11 21:52:28
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 56 ms / 3,000 ms
コード長 805 bytes
コンパイル時間 1,592 ms
コンパイル使用メモリ 25,600 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-07-12 10:53:51
合計ジャッジ時間 4,112 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:38:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |         scanf("%d", &q);
      |         ^~~~~~~~~~~~~~~
main.c:46:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |                 scanf("%d", &t);
      |                 ^~~~~~~~~~~~~~~
main.c:49:25: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |                         scanf("%d", &x);
      |                         ^~~~~~~~~~~~~~~
main.c:55:25: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |                         scanf("%d", &k);
      |                         ^~~~~~~~~~~~~~~

ソースコード

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)
{
	l += ss - 1;
	r += ss - 1;
	int res = -1;
	while (l <= r)
	{
		res = max(res, seg[l]);
		l /= 2;
		res = max(res, seg[r]);
		r = r / 2 - 1;
	}
	return res;
}
int main()
{
	int q;
	scanf("%d", &q);
	int t, x, k;
	int len = 0;
	for (ss = 1; ss < q; ss *= 2);
	for (t = 0; t < 2 * ss - 1; t++)
		seg[t] = -1;
	for (; q > 0; q--)
	{
		scanf("%d", &t);
		if (t == 1)
		{
			scanf("%d", &x);
			update(len, x);
			len++;
		}
		else
		{
			scanf("%d", &k);
			printf("%d\n", get_max(len - k, len - 1));
		}
	}
	return 0;
}
0