結果

問題 No.1891 Static Xor Range Composite Query
ユーザー 👑 ygussanyygussany
提出日時 2022-04-04 22:45:45
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 676 ms / 5,000 ms
コード長 1,251 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 30,092 KB
実行使用メモリ 42,864 KB
最終ジャッジ日時 2023-08-17 00:15:24
合計ジャッジ時間 13,159 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,928 KB
testcase_01 AC 3 ms
14,200 KB
testcase_02 AC 3 ms
14,132 KB
testcase_03 AC 3 ms
14,128 KB
testcase_04 AC 3 ms
14,200 KB
testcase_05 AC 3 ms
14,192 KB
testcase_06 AC 3 ms
14,180 KB
testcase_07 AC 3 ms
14,072 KB
testcase_08 AC 3 ms
14,020 KB
testcase_09 AC 3 ms
14,124 KB
testcase_10 AC 3 ms
14,188 KB
testcase_11 AC 8 ms
26,452 KB
testcase_12 AC 8 ms
26,440 KB
testcase_13 AC 8 ms
26,440 KB
testcase_14 AC 7 ms
26,428 KB
testcase_15 AC 7 ms
26,436 KB
testcase_16 AC 7 ms
26,424 KB
testcase_17 AC 7 ms
26,428 KB
testcase_18 AC 8 ms
26,436 KB
testcase_19 AC 7 ms
26,492 KB
testcase_20 AC 7 ms
26,436 KB
testcase_21 AC 564 ms
42,808 KB
testcase_22 AC 558 ms
42,804 KB
testcase_23 AC 552 ms
42,672 KB
testcase_24 AC 598 ms
42,740 KB
testcase_25 AC 556 ms
42,800 KB
testcase_26 AC 549 ms
42,696 KB
testcase_27 AC 579 ms
42,864 KB
testcase_28 AC 667 ms
42,800 KB
testcase_29 AC 602 ms
42,852 KB
testcase_30 AC 676 ms
42,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int Mod = 998244353, bit[20] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288};
int memo[19][262144][2], a[262144], b[262144];

int recursion(int l, int k, int x)
{
	if (memo[k][l][0] >= 0) return ((long long)memo[k][l][0] * x + memo[k][l][1]) % Mod;
	else if (k == 0) {
		memo[k][l][0] = a[l];
		memo[k][l][1] = b[l];
		return ((long long)a[l] * x + b[l]) % Mod;
	}
	x = recursion(l, k - 1, x);
	x = recursion(l ^ bit[k-1], k - 1, x);
	memo[k][l][0] = (long long)memo[k-1][l][0] * memo[k-1][l ^ bit[k-1]][0] % Mod;
	memo[k][l][1] = ((long long)memo[k-1][l ^ bit[k-1]][0] * memo[k-1][l][1] + memo[k-1][l ^ bit[k-1]][1]) % Mod;
	return x;
}

int solve(int l, int r, int p, int x)
{
	if (l == r) return x;
	
	int i;
	for (i = 1; (l & bit[i-1]) == 0 && l + bit[i] <= r; i++);
	return solve(l + bit[i-1], r, p, recursion(l ^ p, i - 1, x));
}

int main()
{
	int i, N, Q;
	scanf("%d %d", &N, &Q);
	for (i = 0; i < N; i++) scanf("%d %d", &(a[i]), &(b[i]));
	
	int l, r, p, x;
	for (i = 0; bit[i] <= N; i++) for (l = 0; l < N; l++) memo[i][l][0] = -1;
	for (i = 1; i <= Q; i++) {
		scanf("%d %d %d %d", &l, &r, &p, &x);
		printf("%d\n", solve(l, r, p, x));
	}
	return 0;
}
0