AT_arc224_f.AND/OR
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a length-N sequence of non-negative integers A=(A1,A2,…,AN) and an integer K.
Initially, x=0. For i=1,2,…,N in this order, let us choose one of the following two operations to perform.
- Operation 1 : Replace x with x AND Ai.
- Operation 2 : Replace x with x OR Ai.
Here, operation 2 must be chosen at most K times in total. AND denotes the bitwise AND operation, and OR denotes the bitwise OR operation.
Let M be the maximum possible value of x after all operations are finished. Find the number, modulo 998244353, of operation sequences such that the final x equals M.
Here, two operation sequences are distinguished if and only if there exists an integer j (1≤j≤N) such that the operation chosen at the j-th step differs between them.
T test cases are given; solve each of them.
What is the bitwise AND operation?
The bitwise AND of non-negative integers A,B, denoted A AND B, is defined as follows.
- The digit in the 2k (k≥0) place of the binary representation of A AND B is 1 if the corresponding digits of A and B in binary are both 1, and 0 otherwise.
For example, 3 AND 5=1 (in binary: 011 AND 101=001).
What is the bitwise OR operation?
The bitwise OR of non-negative integers A,B, denoted A OR B, is defined as follows.
- The digit in the 2k (k≥0) place of the binary representation of A OR B is 1 if at least one of the corresponding digits of A and B in binary is 1, and 0 otherwise.
For example, 3 OR 5=7 (in binary: 011 OR 101=111).
给你一个长度为 N 的非负整数序列 A=(A1,A2,…,AN) 和一个整数 K。
初始时,x=0。按顺序对 i=1,2,…,N 执行以下两种操作之一:
- 操作 1:将 x 替换为 x AND Ai;
- 操作 2:将 x 替换为 x OR Ai。
其中,操作 2 在整个过程中至多可执行 K 次。AND 表示按位与(bitwise AND)运算,OR 表示按位或(bitwise OR)运算。
令 M 为所有操作完成后 x 可能达到的最大值。求最终 x 恰好等于 M 的操作序列的个数(对 998244353 取模)。
此处,若存在某个整数 j(1≤j≤N),使得两个操作序列在第 j 步所选操作不同,则认为这两个操作序列互不相同。
共给出 T 组测试用例,请分别求解。
什么是按位 AND 运算?
非负整数 A,B 的按位 AND 运算,记作 A AND B,定义如下:
- A AND B 的二进制表示中,2k 位(k≥0)上的数字为 1,当且仅当 A 与 B 的二进制表示中对应位均为 1;否则该位为 0。
例如,3 AND 5=1(二进制:011 AND 101=001)。
什么是按位 OR 运算?
非负整数 A,B 的按位 OR 运算,记作 A OR B,定义如下:
- A OR B 的二进制表示中,2k 位(k≥0)上的数字为 1,当且仅当 A 与 B 的二进制表示中对应位至少有一个为 1;否则该位为 0。
例如,3 OR 5=7(二进制:011 OR 101=111)。
输入格式
The input is given from Standard Input in the following format, where casei denotes the i-th test case:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N K
A1 A2 … AN
输入从标准输入给出,格式如下,其中 casei 表示第 i 个测试用例:
T
case1
case2
⋮
caseT
每个测试用例的格式如下:
N K
A1 A2 … AN
输出格式
Output T lines. The i-th line should contain the answer for the i-th test case.
输出 T 行。第 i 行应包含第 i 个测试用例的答案。
输入输出样例
输入#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=7, and the following three operation sequences achieve the final value x=M.
- Perform the operations in the order 1,1,2,2,2. x changes as 0→0→0→1→3→7.
- Perform the operations in the order 1,2,1,2,2. x changes as 0→0→7→1→3→7.
- Perform the operations in the order 2,1,1,2,2. x changes as 0→3→3→1→3→7.
For the fifth test case, note that the answer should be output modulo 998244353.
Constraints
- 1≤T≤104
- 1≤K≤N≤2×105
- 0≤Ai<260
- The sum of N in each input is at most 2×105.
- All input values are integers.
样例 1 解释:
该输入包含五个测试用例。
对于第一个测试用例,M=7,以下三种操作序列均可使最终值 x=M 成立:
- 按顺序执行操作 1,1,2,2,2。x 的变化过程为 0→0→0→1→3→7。
- 按顺序执行操作 1,2,1,2,2。x 的变化过程为 0→0→7→1→3→7。
- 按顺序执行操作 2,1,1,2,2。x 的变化过程为 0→3→3→1→3→7。
对于第五个测试用例,请注意答案需对 998244353 取模输出。
约束条件
- 1≤T≤104
- 1≤K≤N≤2×105
- 0≤Ai<260
- 所有输入中 N 的总和不超过 2×105。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?