#P9915. 「RiOI-03」3-2

    ID: 10023 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数学洛谷原创O2优化位运算洛谷月赛Ad-hoc

「RiOI-03」3-2

Background

Heart beat to death.

Problem Description

Given a positive integer nn. Write the lowest nn bits of every integer in [0,2n)[0,2^n) in binary, from low to high, into a 2n×n2^n \times n matrix in order. Both dimensions of the matrix are indexed starting from 00. For example, when n=3n=3, the matrix looks like this:

Given qq queries. For each query, ask for the size of the 4-connected component containing the cell at index (x,y)(x,y) in this matrix, modulo 998244353998244353.

Input Format

The first line contains two positive integers n,qn, q.

The next qq lines each contain two non-negative integers x,yx, y, representing one query.

Output Format

Output qq lines, each containing one positive integer, which is the answer for each query modulo 998244353998244353.

2 2
1 1
2 0
3
1

Hint

Sample #1 Explanation

The figure shows the matrix when n=2n=2, where cells with the same color form a 4-connected component.


Constraints

This problem uses bundled testdata.

SubTask\text{SubTask} Score nn\le qq\le
00 55 1515 1515
11 2020 5×1055\times 10^5
22 2525 5×1035\times 10^3
33 5050 101810^{18} 5×1055\times 10^5

For 100%100\% of the testdata, 0y<n10180\le y\lt n\le 10^{18}, 0x<min(2n,1018)0\le x\lt \min(2^n, 10^{18}), 1q5×1051\le q\le 5\times 10^5.

Please use fast input/output methods.

Translated by ChatGPT 5