AT_arc222_e.XOR Matching
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are N cards. The i-th card (1≤i≤N) has the integer Ai written on it. Here, 0≤Ai≤2M−1 holds.
For each integer X=0,1,…,2M−1, let f(X) denote the answer to the following problem:
Consider forming some pairs of cards.
Each pair consists of two distinct cards, and the bitwise XOR of the integers written on those two cards must equal X. The same card cannot be included in multiple pairs.
Find the maximum number of pairs that can be formed under these conditions.
Output the following value:
\[ \left(\sum_{X=0}{2M-1} f(X) \times 10 ^ X\right) \bmod 998244353 \]
What is the bitwise XOR operation
The bitwise XOR of non-negative integers A,B, A⊕B, is defined as follows.
- The digit at the 2k (k≥0) place of A⊕B in binary representation is 1 if exactly one of the digits at the 2k place of A and B in binary representation is 1, and 0 otherwise.
For example, 3⊕5=6 (in binary: 011⊕101=110).
In general, the bitwise XOR of k non-negative integers p1,p2,p3,…,pk is defined as (…((p1⊕p2)⊕p3)⊕⋯⊕pk), and it can be proved that this does not depend on the order of p1,p2,p3,…,pk.
有 N 张卡片。第 i 张卡片(1≤i≤N)上写有一个整数 Ai。其中满足 0≤Ai≤2M−1。
对每个整数 X=0,1,…,2M−1,令 f(X) 表示如下问题的答案:
考虑将若干张卡片两两配对。
每一对由两张互不相同的卡片组成,且这两张卡片上所写整数的按位异或(bitwise XOR)值必须恰好等于 X。同一张卡片不能出现在多个配对中。
在满足上述条件的前提下,求最多能形成多少对。
请输出以下值:
\[ \left(\sum_{X=0}{2M-1} f(X) \times 10 ^ X\right) \bmod 998244353 \]
什么是按位 XOR 运算?
非负整数 A,B 的按位 XOR(记作 A⊕B)定义如下:
- 在二进制表示下,A⊕B 的 2k 位(k≥0)上的数字为 1,当且仅当 A 和 B 在该位上的数字恰好有一个为 1;否则该位为 0。
例如,3⊕5=6(二进制:011⊕101=110)。
一般地,k 个非负整数 p1,p2,p3,…,pk 的按位 XOR 定义为 (…((p1⊕p2)⊕p3)⊕⋯⊕pk),并且可以证明该结果与 p1,p2,p3,…,pk 的顺序无关。
输入格式
The input is given from Standard Input in the following format:
N M
A1 A2 … AN
输入从标准输入给出,格式如下:
N M
A1 A2 … AN
输出格式
Output the following value:
\[ \left(\sum_{X=0}{2M-1} f(X) \times 10 ^ X\right) \bmod 998244353 \]
输出以下值:
\[ \left(\sum_{X=0}{2M-1} f(X) \times 10 ^ X\right) \bmod 998244353 \]
输入输出样例
输入#1
4 2 1 1 3 3
输出#1
202
输入#2
10 3 5 2 1 4 5 5 5 0 1 7
输出#2
22332223
输入#3
10 4 11 6 3 8 6 7 14 10 10 11
输出#3
613668597
说明/提示
Sample 1 Explanation:
- For X=0: two pairs (A1,A2) and (A3,A4) can be formed.
- For X=1: zero pairs can be formed.
- For X=2: two pairs (A1,A4) and (A2,A3) can be formed.
- For X=3: zero pairs can be formed.
Therefore, f(0)=2, f(1)=0, f(2)=2, and f(3)=0. The value to be output is 2×1+0×10+2×100+0×1000=202.
Constraints
- 2≤N≤2×105
- 1≤M≤20
- 0≤Ai≤2M−1 (1≤i≤N)
- All input values are integers.
样例 1 解释:
- 当 X=0 时:可以形成两对 (A1,A2) 和 (A3,A4)。
- 当 X=1 时:无法形成任何对。
- 当 X=2 时:可以形成两对 (A1,A4) 和 (A2,A3)。
- 当 X=3 时:无法形成任何对。
因此,f(0)=2,f(1)=0,f(2)=2,f(3)=0。需输出的值为 2×1+0×10+2×100+0×1000=202。
约束条件
- 2≤N≤2×105
- 1≤M≤20
- 0≤Ai≤2M−1(其中 1≤i≤N)
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?