CF2170C.Quotient and Remainder

普及-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given two integer arrays: q1,q2,…,qnq_1, q_2, \dots, q_n and r1,r2,…,rnr_1, r_2, \dots, r_n, as well as an integer kk.

You can perform the following operation any number of times (possibly zero):

  1. Choose two integers xx and yy such that
    • 1≤y<x≤k1 \le y \lt x \le k;
    • there exists an index ii such that qi=⌊xy⌋q_i = \left\lfloor \frac{x}{y} \right\rfloor (rounded down);
    • there exists an index jj such that rj=x mod yr_j = x \bmod y.
  2. Remove qiq_i from the array qq and rjr_j from the array rr. If there are multiple occurrences of qiq_i in the array qq, only one occurrence is removed; same for rjr_j and the array rr.

Calculate the maximum number of operations that you can perform on the given arrays qq and rr.

给你两个整数数组:q1,q2,…,qnq_1, q_2, \dots, q_n 和 r1,r2,…,rnr_1, r_2, \dots, r_n,以及一个整数 kk。

你可以执行以下操作任意多次(也可以不执行):

  1. 选择两个整数 xx 和 yy,满足:
    • 1≤y<x≤k1 \le y \lt x \le k;
    • 存在某个下标 ii,使得 qi=⌊xy⌋q_i = \left\lfloor \frac{x}{y} \right\rfloor(向下取整);
    • 存在某个下标 jj,使得 rj=x mod yr_j = x \bmod y。
  2. 从数组 qq 中删除 qiq_i,并从数组 rr 中删除 rjr_j。若 qiq_i 在数组 qq 中出现多次,则仅删除其中一次;同理,若 rjr_j 在数组 rr 中出现多次,则也仅删除其中一次。

请计算在给定数组 qq 和 rr 上最多可执行的操作次数。

输入格式

The first line contains one 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≤2⋅1051 \le n \le 2 \cdot 10^5; 2≤k≤10182 \le k \le 10^{18}) — the size of the arrays qq and rr and the upper limit for xx and yy.

The second line of each test case contains nn integers q1,q2,…,qnq_1, q_2, \dots, q_n (1≤qi≤1091 \le q_i \le 10^9) — the array qq.

The third line contains nn integers r1,r2,…,rnr_1, r_2, \dots, r_n (1≤ri≤1091 \le r_i \le 10^9) — the array rr.

Additional constraints on the input: the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

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

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5;2≤k≤10182 \le k \le 10^{18})—— 分别表示数组 qq 和 rr 的大小,以及 xx 和 yy 的上界。

每个测试用例的第二行包含 nn 个整数 q1,q2,…,qnq_1, q_2, \dots, q_n(1≤qi≤1091 \le q_i \le 10^9)—— 即数组 qq。

第三行包含 nn 个整数 r1,r2,…,rnr_1, r_2, \dots, r_n(1≤ri≤1091 \le r_i \le 10^9)—— 即数组 rr。

输入的额外约束:所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print one integer — the maximum number of operations that you can perform on the given arrays.

对于每个测试用例,输出一个整数——即在给定数组上最多可执行的操作次数。

输入输出样例

  • 输入#1

    3
    1 100
    1
    27
    3 10
    5 6 5
    7 1 7
    5 42
    5 4 2 2 1
    9 8 9 8 100

    输出#1

    1
    0
    3

说明/提示

In the first test case, one operation can be performed: you can choose x=69x = 69 and y=42y = 42. Then ⌊6942⌋=1=q1\left\lfloor \frac{69}{42} \right\rfloor = 1 = q_1 and 69 mod 42=27=r169 \bmod 42 = 27 = r_1.

In the second test case, it is impossible to perform any operations, as suitable xx and yy cannot be found.

In the third test case, three operations can be performed:

  1. x=42x = 42, y=17y = 17: ⌊4217⌋=2=q3\left\lfloor \frac{42}{17} \right\rfloor = 2 = q_3 and 42 mod 17=8=r242 \bmod 17 = 8 = r_2;
  2. x=41x = 41, y=16y = 16: ⌊4116⌋=2=q4\left\lfloor \frac{41}{16} \right\rfloor = 2 = q_4 and 41 mod 16=9=r141 \bmod 16 = 9 = r_1;
  3. x=20x = 20, y=12y = 12: ⌊2012⌋=1=q5\left\lfloor \frac{20}{12} \right\rfloor = 1 = q_5 and 20 mod 12=8=r420 \bmod 12 = 8 = r_4;

After these operations, you'll get arrays q=[5,4]q = [5, 4] and r=[9,100]r = [9, 100], and there are no more operations you can perform.

在第一个测试用例中,可以执行一次操作:选择 x=69x = 69 和 y=42y = 42。此时 ⌊6942⌋=1=q1\left\lfloor \frac{69}{42} \right\rfloor = 1 = q_1,且 69 mod 42=27=r169 \bmod 42 = 27 = r_1。

在第二个测试用例中,无法执行任何操作,因为找不到满足条件的 xx 和 yy。

在第三个测试用例中,可以执行三次操作:

  1. x=42x = 42,y=17y = 17:⌊4217⌋=2=q3\left\lfloor \frac{42}{17} \right\rfloor = 2 = q_3,且 42 mod 17=8=r242 \bmod 17 = 8 = r_2;
  2. x=41x = 41,y=16y = 16:⌊4116⌋=2=q4\left\lfloor \frac{41}{16} \right\rfloor = 2 = q_4,且 41 mod 16=9=r141 \bmod 16 = 9 = r_1;
  3. x=20x = 20,y=12y = 12:⌊2012⌋=1=q5\left\lfloor \frac{20}{12} \right\rfloor = 1 = q_5,且 20 mod 12=8=r420 \bmod 12 = 8 = r_4;

执行完这些操作后,得到数组 q=[5,4]q = [5, 4] 和 r=[9,100]r = [9, 100],此后无法再执行任何操作。

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

首页