結果

問題 No.2942 Sigma Music Game Level Problem
ユーザー pengin_2000pengin_2000
提出日時 2024-10-18 23:28:34
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 649 ms / 6,000 ms
コード長 1,335 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 30,976 KB
実行使用メモリ 28,640 KB
最終ジャッジ日時 2024-10-18 23:28:59
合計ジャッジ時間 9,812 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
16,112 KB
testcase_01 AC 4 ms
16,108 KB
testcase_02 AC 4 ms
16,240 KB
testcase_03 AC 4 ms
16,112 KB
testcase_04 AC 4 ms
16,240 KB
testcase_05 AC 4 ms
16,236 KB
testcase_06 AC 4 ms
16,116 KB
testcase_07 AC 4 ms
16,116 KB
testcase_08 AC 5 ms
16,244 KB
testcase_09 AC 4 ms
16,116 KB
testcase_10 AC 4 ms
16,240 KB
testcase_11 AC 256 ms
21,884 KB
testcase_12 AC 586 ms
27,840 KB
testcase_13 AC 543 ms
24,684 KB
testcase_14 AC 285 ms
24,212 KB
testcase_15 AC 211 ms
23,372 KB
testcase_16 AC 485 ms
21,396 KB
testcase_17 AC 130 ms
19,040 KB
testcase_18 AC 359 ms
23,372 KB
testcase_19 AC 649 ms
23,796 KB
testcase_20 AC 170 ms
20,668 KB
testcase_21 AC 576 ms
27,996 KB
testcase_22 AC 529 ms
28,156 KB
testcase_23 AC 198 ms
19,656 KB
testcase_24 AC 4 ms
16,240 KB
testcase_25 AC 4 ms
16,112 KB
testcase_26 AC 506 ms
28,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int seg[2][1000006], ss;
void update(long long int z, long long int x, long long int d)
{
	x += ss - 1;
	seg[z][x] += d;
	while (x > 0)
	{
		x = (x - 1) / 2;
		seg[z][x] = seg[z][2 * x + 1] + seg[z][2 * x + 2];
	}
	return;
}
long long int get(long long int z, long long int l, long long int r)
{
	l += ss - 1;
	r += ss - 1;
	long long int res = 0;
	while (l < r)
	{
		if (l % 2 == 0)
			res += seg[z][l];
		l /= 2;
		if (r % 2 > 0)
			res += seg[z][r];
		r = r / 2 - 1;
	}
	if (l == r)
		res += seg[z][l];
	return res;
}
long long int L[1000006];
long long int a[1000006];
int main()
{
	long long int n, q;
	scanf("%lld %lld %lld", &n, &q, &L[0]);
	long long int i;
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	for (ss = 1; ss < 200005; ss *= 2);
	for (i = 0; i < 2 * ss - 1; i++)
		seg[0][i] = seg[1][i] = 0;
	for (i = 0; i < n; i++)
	{
		update(0, a[i], 1);
		update(1, a[i], a[i]);
	}
	long long int t, l, r, cnt = 0;
	for (i = 1; i <= q; i++)
	{
		L[i] = L[i - 1];
		scanf("%lld", &t);
		if (t == 1)
		{
			scanf("%lld", &l);
			update(0, l, 1);
			update(1, l, l);
		}
		else if (t == 2)
		{
			scanf("%lld %lld", &l, &r);
			printf("%lld %lld\n", get(0, l, r), get(1, l, r));
			cnt++;
		}
		else
		{
			scanf("%lld", &l);
			L[i] = l;
		}
	}
	if (cnt == 0)
		printf("Not Found!\n");
	return 0;
}
0