結果

問題 No.2462 七人カノン
ユーザー 👑 ygussanyygussany
提出日時 2023-09-08 21:39:54
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,724 bytes
コンパイル時間 1,441 ms
コンパイル使用メモリ 30,412 KB
実行使用メモリ 6,904 KB
最終ジャッジ日時 2023-09-08 21:40:03
合計ジャッジ時間 8,135 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,404 KB
testcase_01 AC 2 ms
4,700 KB
testcase_02 AC 2 ms
4,868 KB
testcase_03 AC 3 ms
4,548 KB
testcase_04 AC 3 ms
4,508 KB
testcase_05 AC 3 ms
4,872 KB
testcase_06 AC 3 ms
5,932 KB
testcase_07 AC 2 ms
4,424 KB
testcase_08 AC 3 ms
4,384 KB
testcase_09 AC 2 ms
5,956 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 77 ms
6,076 KB
testcase_14 AC 81 ms
6,192 KB
testcase_15 AC 75 ms
6,156 KB
testcase_16 AC 88 ms
6,496 KB
testcase_17 AC 87 ms
6,380 KB
testcase_18 AC 24 ms
4,380 KB
testcase_19 AC 25 ms
4,712 KB
testcase_20 AC 76 ms
6,796 KB
testcase_21 AC 77 ms
6,852 KB
testcase_22 AC 78 ms
6,904 KB
testcase_23 AC 76 ms
6,844 KB
testcase_24 AC 57 ms
5,604 KB
testcase_25 AC 86 ms
6,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[100001];
	int size;
} min_heap;

void push(min_heap* h, data x)
{
	int i = ++(h->size), j = i >> 1;
	data tmp;
	h->obj[i] = x;
	while (j > 0) {
		if (h->obj[i].key < h->obj[j].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j >>= 1;
		} else break;
	}
}

data pop(min_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key < h->obj[j].key) j ^= 1;
		if (h->obj[j].key < h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j <<= 1;
		} else break;
	}
	return output;
}

int main()
{
	int i, N, Q, I[100001], S[100001], T[100001];
	scanf("%d %d", &N, &Q);
	for (i = 1; i <= Q; i++) scanf("%d %d %d", &(I[i]), &(S[i]), &(T[i]));
	
	int num[100003] = {}, tmp;
	double sum[100003];
	for (i = 1; i <= Q; i++) {
		num[S[i]+1]++;
		num[T[i]+1]--;
	}
	for (i = 1, tmp = 0, sum[0] = 0.0; i <= 100000; i++) {
		tmp += num[i];
		num[i] = tmp;
		sum[i] = sum[i-1] + ((num[i] > 0)? 1.0 / num[i]: 0.0);
	}
	
	int beg[100001] = {};
	double ans[100001] = {};
	min_heap h[2];
	data d;
	h[0].size = 0;
	h[1].size = 0;
	for (i = 1; i <= Q; i++) {
		d.key = S[i];
		d.id = i;
		push(&(h[0]), d);
	}
	for (i = 0; i <= 100000; i++) {
		while (h[0].size > 0 && h[0].obj[1].key == i) {
			d = pop(&(h[0]));
			beg[I[d.id]] = i;
			d.key = T[d.id];
			push(&(h[1]), d);
		}
		while (h[1].size > 0 && h[1].obj[1].key == i) {
			d = pop(&(h[1]));
			ans[I[d.id]] += sum[i] - sum[beg[I[d.id]]];
		}
	}
	for (i = 1; i <= N; i++) printf("%.6f\n", ans[i]);
	fflush(stdout);
	return 0;
}
0