AT_arc222_e.XOR Matching

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There are NN cards. The ii-th card (1≤i≤N1\leq i\leq N) has the integer AiA_i written on it. Here, 0≤Ai≤2M−10\leq A_i \leq 2^M-1 holds.

For each integer X=0,1,…,2M−1X=0,1,\ldots,2^M-1, let f(X)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 XX. 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\mathrm{XOR} operation

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

  • The digit at the 2k2^k (k≥0k \geq 0) place of A⊕BA \oplus B in binary representation is 11 if exactly one of the digits at the 2k2^k place of AA and BB in binary representation is 11, and 00 otherwise.

For example, 3⊕5=63 \oplus 5 = 6 (in binary: 011⊕101=110011 \oplus 101 = 110).
In general, the bitwise XOR\mathrm{XOR} of kk non-negative integers p1,p2,p3,…,pkp_1, p_2, p_3, \dots, p_k is defined as (…((p1⊕p2)⊕p3)⊕⋯⊕pk)(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k), and it can be proved that this does not depend on the order of p1,p2,p3,…,pkp_1, p_2, p_3, \dots, p_k.

有 NN 张卡片。第 ii 张卡片(1≤i≤N1\leq i\leq N)上写有一个整数 AiA_i。其中满足 0≤Ai≤2M−10\leq A_i \leq 2^M-1。

对每个整数 X=0,1,…,2M−1X=0,1,\ldots,2^M-1,令 f(X)f(X) 表示如下问题的答案:

考虑将若干张卡片两两配对。

每一对由两张互不相同的卡片组成,且这两张卡片上所写整数的按位异或(bitwise XOR)值必须恰好等于 XX。同一张卡片不能出现在多个配对中。

在满足上述条件的前提下,求最多能形成多少对。

请输出以下值:

\[ \left(\sum_{X=0}{2M-1} f(X) \times 10 ^ X\right) \bmod 998244353 \]

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

非负整数 A,BA, B 的按位 XOR\mathrm{XOR}(记作 A⊕BA \oplus B)定义如下:

  • 在二进制表示下,A⊕BA \oplus B 的 2k2^k 位(k≥0k \geq 0)上的数字为 11,当且仅当 AA 和 BB 在该位上的数字恰好有一个为 11;否则该位为 00。

例如,3⊕5=63 \oplus 5 = 6(二进制:011⊕101=110011 \oplus 101 = 110)。
一般地,kk 个非负整数 p1,p2,p3,…,pkp_1, p_2, p_3, \dots, p_k 的按位 XOR\mathrm{XOR} 定义为 (…((p1⊕p2)⊕p3)⊕⋯⊕pk)(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k),并且可以证明该结果与 p1,p2,p3,…,pkp_1, p_2, p_3, \dots, p_k 的顺序无关。

输入格式

The input is given from Standard Input in the following format:

NN MM
A1A_1 A2A_2 …\ldots ANA_N

输入从标准输入给出,格式如下:

NN MM
A1A_1 A2A_2 …\ldots ANA_N

输出格式

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=0X=0: two pairs (A1,A2)(A_1,A_2) and (A3,A4)(A_3,A_4) can be formed.
  • For X=1X=1: zero pairs can be formed.
  • For X=2X=2: two pairs (A1,A4)(A_1,A_4) and (A2,A3)(A_2,A_3) can be formed.
  • For X=3X=3: zero pairs can be formed.

Therefore, f(0)=2f(0)=2, f(1)=0f(1)=0, f(2)=2f(2)=2, and f(3)=0f(3)=0. The value to be output is 2×1+0×10+2×100+0×1000=2022\times 1 + 0\times 10 + 2\times 100 + 0\times 1000 = 202.

Constraints

  • 2≤N≤2×1052\leq N\leq 2\times 10^5
  • 1≤M≤201\leq M\leq 20
  • 0≤Ai≤2M−10\leq A_i \leq 2^M-1 (1≤i≤N1\leq i\leq N)
  • All input values are integers.

样例 1 解释:

  • 当 X=0X=0 时:可以形成两对 (A1,A2)(A_1,A_2) 和 (A3,A4)(A_3,A_4)。
  • 当 X=1X=1 时:无法形成任何对。
  • 当 X=2X=2 时:可以形成两对 (A1,A4)(A_1,A_4) 和 (A2,A3)(A_2,A_3)。
  • 当 X=3X=3 时:无法形成任何对。

因此,f(0)=2f(0)=2,f(1)=0f(1)=0,f(2)=2f(2)=2,f(3)=0f(3)=0。需输出的值为 2×1+0×10+2×100+0×1000=2022\times 1 + 0\times 10 + 2\times 100 + 0\times 1000 = 202。

约束条件

  • 2≤N≤2×1052\leq N\leq 2\times 10^5
  • 1≤M≤201\leq M\leq 20
  • 0≤Ai≤2M−10\leq A_i \leq 2^M-1(其中 1≤i≤N1\leq i\leq N)
  • 所有输入值均为整数。

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

首页