CF2225D.Exceptional Segments

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given two integers $ n $ and $ x $ .

Consider the sequence $ [1, 2, 3, \dots, n] $ . You need to find the number of its subsegments that contain $ x $ and have XOR equal to $ 0 $ . In other words, you need to count the number of pairs $ (l, r) $ such that $ 1 \le l \le x \le r \le n $ and $ l \oplus (l+1) \oplus \dots \oplus r = 0 $ , where $ \oplus $ denotes the bitwise exclusive OR.

For example, if $ n = 7 $ and $ x = 6 $ , then the following segments are suitable:

  • $ (4, 7) $ , because $ x $ lies in this segment and $ 4 \oplus 5 \oplus 6 \oplus 7 = 0 $ ;
  • $ (1, 7) $ , because $ x $ lies in this segment and $ 1 \oplus 2 \oplus 3 \oplus 4 \oplus 5 \oplus 6 \oplus 7 = 0 $ .

Since the answer can be very large, output it modulo $ 998,244,353 $ .

输入格式

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

The only line of each test case contains two integers $ n $ and $ x $ ( $ 1 \le x \le n \le 10^{18} $ ).

输出格式

For each test case, output one integer — the number of suitable segments modulo $ 998,244,353 $ .

输入输出样例

  • 输入#1

    5
    5 5
    8 1
    15 8
    10 10
    5989566119 1996588700

    输出#1

    1
    2
    10
    0
    99996

说明/提示

null

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

首页