CF1864E.Guess Game

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Carol has a sequence ss of nn non-negative integers. She wants to play the "Guess Game" with Alice and Bob.

To play the game, Carol will randomly select two integer indices iai_a and ibi_b within the range [1,n][1, n] , and set a=siaa=s_{i_a} , b=sibb=s_{i_b} . Please note that iai_a and ibi_b may coincide.

Carol will tell:

  • the value of aa to Alice;
  • the value of bb to Bob;
  • the value of aba \mid b to both Alice and Bob, where | denotes the bitwise OR operation.

Please note that Carol will not tell any information about ss to either Alice or Bob.

Then the guessing starts. The two players take turns making guesses, with Alice starting first. The goal of both players is to establish which of the following is true: a<ba < b , a>ba > b , or a=ba = b .

In their turn, a player can do one of the following two things:

  • say "I don't know", and pass the turn to the other player;
  • say "I know", followed by the answer " a<ba<b ", " a>ba>b ", or " a=ba=b "; then the game ends.

Alice and Bob hear what each other says, and can use this information to deduce the answer. Both Alice and Bob are smart enough and only say "I know" when they are completely sure.

You need to calculate the expected value of the number of turns taken by players in the game. Output the answer modulo 998244353998\,244\,353 .

Formally, let M=998244353M = 998\,244\,353 . It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q} , where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M} . Output the integer equal to pq1modMp \cdot q^{-1} \bmod M . In other words, output such an integer xx that 0x<M0 \le x < M and xqp(modM)x \cdot q \equiv p \pmod{M} .

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1051 \le t \le 10^5 ). The description of the test cases follows.

The first line of each testcase contains a single integer nn ( 1n21051 \le n \le 2\cdot 10^5 ).

The second line of each testcase contains nn integers s1,s2,,sns_1,s_2,\ldots, s_n ( 0si<2300 \le s_i < 2^{30} ).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, print a single integer — the answer to the problem modulo 998244353998\,244\,353 .

输入输出样例

  • 输入#1

    4
    2
    2 3
    3
    0 0 0
    3
    9 9 6
    8
    34124838 0 113193378 8 321939321 113193378 9463828 99

    输出#1

    499122179
    1
    332748120
    77987843

说明/提示

In the first test case, there are only 44 possible situations:

  1. ia=1i_a=1 , ib=1i_b=1 , a=2a=2 , b=2b=2 , the number of turns is 22 ;
  2. ia=1i_a=1 , ib=2i_b=2 , a=2a=2 , b=3b=3 , the number of turns is 33 ;
  3. ia=2i_a=2 , ib=1i_b=1 , a=3a=3 , b=2b=2 , the number of turns is 22 ;
  4. ia=2i_a=2 , ib=2i_b=2 , a=3a=3 , b=3b=3 , the number of turns is 33 .

The expected number of turns is 2+3+2+34=52=499122179(mod998244353)\frac{2+3+2+3}{4}=\frac{5}{2}=499122179\pmod{998244353} .

Consider the first case, when a=2a=2 , b=2b=2 . The guessing process is as follows.

In the first turn, Alice thinks, "I know that a=2,ab=2a=2, a\mid b=2 . I can infer that b=0b=0 or b=2b=2 , but I am not sure which one". Thus, she says, "I don't know".

In the second turn, Bob thinks, "I know that b=2,ab=2b=2, a\mid b=2 . I can infer that a=0a=0 or a=2a=2 . But if a=0a=0 , then Alice would have already said that a<ba<b in the first turn, but she hasn't. So a=2a=2 ". Thus, he says, "I know, a=ba=b ". The game ends.

In the second test case, for a=0a=0 , b=0b=0 , Alice knows that a=ba=b immediately. The expected number of turns equals 11 .

首页