CF1917D.Yet Another Inversions Problem

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a permutation p0,p1,…,pn−1p_0, p_1, \ldots, p_{n-1} of odd integers from 11 to 2n−12n-1 and a permutation q0,q1,…,qk−1q_0, q_1, \ldots, q_{k-1} of integers from 00 to k−1k-1.

An array a0,a1,…,ank−1a_0, a_1, \ldots, a_{nk-1} of length nknk is defined as follows:

ai⋅k+j=pi⋅2qja_{i \cdot k+j}=p_i \cdot 2^{q_j} for all 0≤i<n0 \le i \lt n and all 0≤j<k0 \le j \lt k

For example, if p=[3,5,1]p = [3, 5, 1] and q=[0,1]q = [0, 1], then a=[3,6,5,10,1,2]a = [3, 6, 5, 10, 1, 2].

Note that all arrays in the statement are zero-indexed. Note that each element of the array aa is uniquely determined.

Find the number of inversions in the array aa. Since this number can be very large, you should find only its remainder modulo 998 244 353998\,244\,353.

An inversion in array aa is a pair (i,j)(i, j) (0≤i<j<nk0 \le i \lt j \lt nk) such that ai>aja_i \gt a_j.

给你一个由 11 到 2n−12n-1 的奇数组成的排列 p0,p1,…,pn−1p_0, p_1, \ldots, p_{n-1},以及一个由 00 到 k−1k-1 的整数组成的排列 q0,q1,…,qk−1q_0, q_1, \ldots, q_{k-1}。

定义一个长度为 nknk 的数组 a0,a1,…,ank−1a_0, a_1, \ldots, a_{nk-1} 如下:

对所有满足 0≤i<n0 \le i \lt n 和 0≤j<k0 \le j \lt k 的 i,ji, j,有

ai⋅k+j=pi⋅2qja_{i \cdot k+j}=p_i \cdot 2^{q_j}

例如,若 p=[3,5,1]p = [3, 5, 1] 且 q=[0,1]q = [0, 1],则 a=[3,6,5,10,1,2]a = [3, 6, 5, 10, 1, 2]。

注意:题目中所有数组均采用零起点索引(zero-indexed)。注意:数组 aa 的每个元素均由上述规则唯一确定。

请计算数组 aa 中逆序对(inversion)的个数。由于该数目可能非常大,你只需输出其对 998 244 353998\,244\,353 取模的结果。

数组 aa 中的一个逆序对是指一对下标 (i,j)(i, j)(满足 0≤i<j<nk0 \le i \lt j \lt nk),使得 ai>aja_i \gt a_j。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains two integers nn and kk (1≤n,k≤2⋅1051 \le n, k \le 2 \cdot 10^5) — the lengths of arrays pp and qq.

The second line of each test case contains nn distinct integers p0,p1,…,pn−1p_0, p_1, \ldots, p_{n-1} (1≤pi≤2n−11 \le p_i \le 2n-1, pip_i is odd) — the array pp.

The third line of each test case contains kk distinct integers q0,q1,…,qk−1q_0, q_1, \ldots, q_{k-1} (0≤qi<k0 \le q_i \lt k) — the array qq.

It is guaranteed that the sum of nn over all test cases doesn't exceed 2⋅1052 \cdot 10^5 and the sum of kk over all test cases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n,k≤2⋅1051 \le n, k \le 2 \cdot 10^5)—— 数组 pp 和 qq 的长度。

每个测试用例的第二行包含 nn 个互不相同的整数 p0,p1,…,pn−1p_0, p_1, \ldots, p_{n-1}(1≤pi≤2n−11 \le p_i \le 2n-1,且每个 pip_i 均为奇数)—— 数组 pp。

每个测试用例的第三行包含 kk 个互不相同的整数 q0,q1,…,qk−1q_0, q_1, \ldots, q_{k-1}(0≤qi<k0 \le q_i \lt k)—— 数组 qq。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5,且所有测试用例中 kk 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output one integer: the number of inversions in array aa modulo 998 244 353998\,244\,353.

对于每个测试用例,输出一个整数:数组 aa 中逆序对的数量对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    4
    3 2
    3 5 1
    0 1
    3 4
    1 3 5
    3 2 0 1
    1 5
    1
    0 1 2 3 4
    8 3
    5 1 7 11 15 3 9 13
    2 0 1

    输出#1

    9
    25
    0
    104

说明/提示

In the first test case, array aa is equal to [3,6,5,10,1,2][3, 6, 5, 10, 1, 2]. There are 99 inversions in it: (0,4)(0, 4), (0,5)(0, 5), (1,2)(1, 2), (1,4)(1, 4), (1,5)(1, 5), (2,4)(2, 4), (2,5)(2, 5), (3,4)(3, 4), (3,5)(3, 5). Note that these are pairs (i,j)(i, j) such that i<ji \lt j and ai>aja_i \gt a_j.

In the second test case, array aa is equal to [8,4,1,2,24,12,3,6,40,20,5,10][8, 4, 1, 2, 24, 12, 3, 6, 40, 20, 5, 10]. There are 2525 inversions in it.

In the third test case, array aa is equal to [1,2,4,8,16][1, 2, 4, 8, 16]. There are no inversions in it.

在第一个测试用例中,数组 aa 等于 [3,6,5,10,1,2][3, 6, 5, 10, 1, 2]。其中包含 99 个逆序对:(0,4)(0, 4)、(0,5)(0, 5)、(1,2)(1, 2)、(1,4)(1, 4)、(1,5)(1, 5)、(2,4)(2, 4)、(2,5)(2, 5)、(3,4)(3, 4)、(3,5)(3, 5)。注意,这些是满足 i<ji \lt j 且 ai>aja_i \gt a_j 的下标对 (i,j)(i, j)。

在第二个测试用例中,数组 aa 等于 [8,4,1,2,24,12,3,6,40,20,5,10][8, 4, 1, 2, 24, 12, 3, 6, 40, 20, 5, 10]。其中包含 2525 个逆序对。

在第三个测试用例中,数组 aa 等于 [1,2,4,8,16][1, 2, 4, 8, 16]。其中不包含任何逆序对。

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

首页