AT_arc224_f.AND/OR

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a length-NN sequence of non-negative integers A=(A1,A2,…,AN)A=(A_1,A_2,\dots,A_N) and an integer KK.

Initially, x=0x=0. For i=1,2,…,Ni=1,2,\dots,N in this order, let us choose one of the following two operations to perform.

  • Operation 11 : Replace xx with xx AND{\rm AND} AiA_i.
  • Operation 22 : Replace xx with xx OR{\rm OR} AiA_i.

Here, operation 22 must be chosen at most KK times in total. AND{\rm AND} denotes the bitwise AND{\rm AND} operation, and OR{\rm OR} denotes the bitwise OR{\rm OR} operation.

Let MM be the maximum possible value of xx after all operations are finished. Find the number, modulo 998244353998244353, of operation sequences such that the final xx equals MM.

Here, two operation sequences are distinguished if and only if there exists an integer jj (1≤j≤N1 \le j \le N) such that the operation chosen at the jj-th step differs between them.

TT test cases are given; solve each of them.

What is the bitwise AND\mathrm{AND} operation?

The bitwise AND\mathrm{AND} of non-negative integers A,BA, B, denoted A AND BA\ \mathrm{AND}\ B, is defined as follows.

  • The digit in the 2k2^k (k≥0k \geq 0) place of the binary representation of A AND BA\ \mathrm{AND}\ B is 11 if the corresponding digits of AA and BB in binary are both 11, and 00 otherwise.

For example, 3 AND 5=13\ \mathrm{AND}\ 5 = 1 (in binary: 011 AND 101=001011\ \mathrm{AND}\ 101 = 001).

What is the bitwise OR\mathrm{OR} operation?

The bitwise OR\mathrm{OR} of non-negative integers A,BA, B, denoted A OR BA\ \mathrm{OR}\ B, is defined as follows.

  • The digit in the 2k2^k (k≥0k \geq 0) place of the binary representation of A OR BA\ \mathrm{OR}\ B is 11 if at least one of the corresponding digits of AA and BB in binary is 11, and 00 otherwise.

For example, 3 OR 5=73\ \mathrm{OR}\ 5 = 7 (in binary: 011 OR 101=111011\ \mathrm{OR}\ 101 = 111).

给你一个长度为 NN 的非负整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\dots,A_N) 和一个整数 KK。

初始时,x=0x=0。按顺序对 i=1,2,…,Ni=1,2,\dots,N 执行以下两种操作之一:

  • 操作 11:将 xx 替换为 x AND Aix\ \mathrm{AND}\ A_i;
  • 操作 22:将 xx 替换为 x OR Aix\ \mathrm{OR}\ A_i。

其中,操作 22 在整个过程中至多可执行 KK 次。AND\mathrm{AND} 表示按位与(bitwise AND)运算,OR\mathrm{OR} 表示按位或(bitwise OR)运算。

令 MM 为所有操作完成后 xx 可能达到的最大值。求最终 xx 恰好等于 MM 的操作序列的个数(对 998244353998244353 取模)。

此处,若存在某个整数 jj(1≤j≤N1 \le j \le N),使得两个操作序列在第 jj 步所选操作不同,则认为这两个操作序列互不相同。

共给出 TT 组测试用例,请分别求解。

什么是按位 AND\mathrm{AND} 运算?

非负整数 A,BA, B 的按位 AND\mathrm{AND} 运算,记作 A AND BA\ \mathrm{AND}\ B,定义如下:

  • A AND BA\ \mathrm{AND}\ B 的二进制表示中,2k2^k 位(k≥0k \geq 0)上的数字为 11,当且仅当 AA 与 BB 的二进制表示中对应位均为 11;否则该位为 00。

例如,3 AND 5=13\ \mathrm{AND}\ 5 = 1(二进制:011 AND 101=001011\ \mathrm{AND}\ 101 = 001)。

什么是按位 OR\mathrm{OR} 运算?

非负整数 A,BA, B 的按位 OR\mathrm{OR} 运算,记作 A OR BA\ \mathrm{OR}\ B,定义如下:

  • A OR BA\ \mathrm{OR}\ B 的二进制表示中,2k2^k 位(k≥0k \geq 0)上的数字为 11,当且仅当 AA 与 BB 的二进制表示中对应位至少有一个为 11;否则该位为 00。

例如,3 OR 5=73\ \mathrm{OR}\ 5 = 7(二进制:011 OR 101=111011\ \mathrm{OR}\ 101 = 111)。

输入格式

The input is given from Standard Input in the following format, where casei\mathrm{case}_i denotes the ii-th test case:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

NN KK
A1A_1 A2A_2 …\dots ANA_N

输入从标准输入给出,格式如下,其中 casei\mathrm{case}_i 表示第 ii 个测试用例:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例的格式如下:

NN KK
A1A_1 A2A_2 …\dots ANA_N

输出格式

Output TT lines. The ii-th line should contain the answer for the ii-th test case.

输出 TT 行。第 ii 行应包含第 ii 个测试用例的答案。

输入输出样例

  • 输入#1

    5
    5 3
    3 7 1 2 6
    1 1
    1
    10 8
    3 1 4 1 5 9 2 6 5 3
    10 5
    227966327241983404 430356836747706085 918791034668488208 753980266897555955 1090352658151595591 1077218377572152409 641276315925917062 859382256805178767 103741332934325112 1090530740094421349
    33 33
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

    输出#1

    3
    1
    26
    1
    603979768

说明/提示

Sample 1 Explanation:
This input contains five test cases.

For the first test case, M=7M=7, and the following three operation sequences achieve the final value x=Mx=M.

  • Perform the operations in the order 1,1,2,2,21,1,2,2,2. xx changes as 0→0→0→1→3→70 \to 0 \to 0 \to 1 \to 3 \to 7.
  • Perform the operations in the order 1,2,1,2,21,2,1,2,2. xx changes as 0→0→7→1→3→70 \to 0 \to 7 \to 1 \to 3 \to 7.
  • Perform the operations in the order 2,1,1,2,22,1,1,2,2. xx changes as 0→3→3→1→3→70 \to 3 \to 3 \to 1 \to 3 \to 7.

For the fifth test case, note that the answer should be output modulo 998244353998244353.

Constraints

  • 1≤T≤1041 \le T \le 10^4
  • 1≤K≤N≤2×1051 \le K \le N \le 2 \times 10^5
  • 0≤Ai<2600 \le A_i < 2^{60}
  • The sum of NN in each input is at most 2×1052 \times 10^5.
  • All input values are integers.

样例 1 解释:
该输入包含五个测试用例。

对于第一个测试用例,M=7M=7,以下三种操作序列均可使最终值 x=Mx=M 成立:

  • 按顺序执行操作 1,1,2,2,21,1,2,2,2。xx 的变化过程为 0→0→0→1→3→70 \to 0 \to 0 \to 1 \to 3 \to 7。
  • 按顺序执行操作 1,2,1,2,21,2,1,2,2。xx 的变化过程为 0→0→7→1→3→70 \to 0 \to 7 \to 1 \to 3 \to 7。
  • 按顺序执行操作 2,1,1,2,22,1,1,2,2。xx 的变化过程为 0→3→3→1→3→70 \to 3 \to 3 \to 1 \to 3 \to 7。

对于第五个测试用例,请注意答案需对 998244353998244353 取模输出。

约束条件

  • 1≤T≤1041 \le T \le 10^4
  • 1≤K≤N≤2×1051 \le K \le N \le 2 \times 10^5
  • 0≤Ai<2600 \le A_i < 2^{60}
  • 所有输入中 NN 的总和不超过 2×1052 \times 10^5。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页