結果

問題 No.3197 Frequency Counter
ユーザー pengin_2000
提出日時 2025-07-11 21:35:43
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 1,519 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 27,056 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-07-11 21:35:51
合計ジャッジ時間 2,928 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:89:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   89 |         scanf("%d", &n);
      |         ^~~~~~~~~~~~~~~
main.c:92:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   92 |                 scanf("%d", &a[i]);
      |                 ^~~~~~~~~~~~~~~~~~
main.c:99:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   99 |         scanf("%d", &q);
      |         ^~~~~~~~~~~~~~~
main.c:102:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  102 |                 scanf("%d %d", &x, &k);
      |                 ^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
int h[200005], 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++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
int pop()
{
	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];
}
int a[200005];
int n;
int count(int x)
{
	int min, mid, max, left, right;
	min = -1;
	max = n;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (a[mid] < x)
			min = mid;
		else
			max = mid;
	}
	left = max;
	min = -1;
	max = n;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (a[mid] > x)
			max = mid;
		else
			min = mid;
	}
	right = max;
	return right - left;
}
int main()
{
	scanf("%d", &n);
	int i;
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	l = 0;
	for (i = 0; i < n; i++)
		push(a[i]);
	for (i = 0; i < n; i++)
		a[i] = pop();
	int q, x, k;
	scanf("%d", &q);
	for (; q > 0; q--)
	{
		scanf("%d %d", &x, &k);
		if (count(x) < k)
			printf("No\n");
		else
			printf("Yes\n");
	}
	return 0;
}
0