CF979D.Kuro and GCD and XOR and SUM

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Kuro is currently playing an educational game about numbers. The game focuses on the greatest common divisor (GCD), the XOR value, and the sum of two numbers. Kuro loves the game so much that he solves levels by levels day by day.

Sadly, he's going on a vacation for a day, and he isn't able to continue his solving streak on his own. As Katie is a reliable person, Kuro kindly asked her to come to his house on this day to play the game for him.

Initally, there is an empty array aa. The game consists of qq tasks of two types. The first type asks Katie to add a number uiu_i to aa. The second type asks Katie to find a number vv existing in aa such that ki∣GCD(xi,v)k_i \mid GCD(x_i, v), xi+v≤six_i + v \leq s_i, and xi⊕vx_i \oplus v is maximized, where ⊕\oplus denotes the bitwise XOR operation, GCD(c,d)GCD(c, d) denotes the greatest common divisor of integers cc and dd, and y∣xy \mid x means xx is divisible by yy, or report -1 if no such numbers are found.

Since you are a programmer, Katie needs you to automatically and accurately perform the tasks in the game to satisfy her dear friend Kuro. Let's help her!

Kuro 正在玩一款关于数字的教育类游戏。该游戏聚焦于最大公约数(GCD)、异或值(XOR) 以及两数之和。Kuro 非常喜爱这款游戏,因此日复一日地逐关攻克。

遗憾的是,他即将外出度假一天,无法独自延续自己的闯关纪录。由于 Katie 是一位值得信赖的人,Kuro 恳请她当天到自己家中代为玩游戏。

初始时,存在一个空数组 aa。游戏共包含 qq 个任务,分为两类:

  • 第一类任务要求 Katie 将一个数 uiu_i 加入数组 aa;
  • 第二类任务要求 Katie 在 aa 中找出一个已存在的数 vv,使得同时满足以下三个条件:
    • ki∣GCD(xi,v)k_i \mid GCD(x_i, v)(即 GCD(xi,v)GCD(x_i, v) 能被 kik_i 整除),
    • xi+v≤six_i + v \leq s_i,
    • xi⊕vx_i \oplus v 的值尽可能大(其中 ⊕\oplus 表示按位异或运算);
      若不存在满足条件的 vv,则报告 -1。

由于你是一名程序员,Katie 需要你自动且准确地完成游戏中所有任务,以满足她亲爱的朋友 Kuro。让我们来帮她吧!

输入格式

The first line contains one integer qq (2≤q≤1052 \leq q \leq 10^{5}) — the number of tasks the game wants you to perform.

qq lines follow, each line begins with an integer tit_i — the type of the task:

  • If ti=1t_i = 1, an integer uiu_i follow (1≤ui≤1051 \leq u_i \leq 10^{5}) — you have to add uiu_i to the array aa.
  • If ti=2t_i = 2, three integers xix_i, kik_i, and sis_i follow (1≤xi,ki,si≤1051 \leq x_i, k_i, s_i \leq 10^{5}) — you must find a number vv existing in the array aa such that ki∣GCD(xi,v)k_i \mid GCD(x_i, v), xi+v≤six_i + v \leq s_i, and xi⊕vx_i \oplus v is maximized, where ⊕\oplus denotes the XOR operation, or report -1 if no such numbers are found.

It is guaranteed that the type of the first task is type 11, and there exists at least one task of type 22.

第一行包含一个整数 qq(2≤q≤1052 \leq q \leq 10^{5})—— 表示游戏要求你执行的任务数量。

接下来有 qq 行,每行以一个整数 tit_i 开头,表示该任务的类型:

  • 若 ti=1t_i = 1,则其后跟一个整数 uiu_i(1≤ui≤1051 \leq u_i \leq 10^{5})—— 你需要将 uiu_i 加入数组 aa 中。
  • 若 ti=2t_i = 2,则其后跟三个整数 xix_i、kik_i 和 sis_i(1≤xi,ki,si≤1051 \leq x_i, k_i, s_i \leq 10^{5})—— 你需要在数组 aa 中找出一个数 vv,使得满足以下条件:
    • ki∣GCD(xi,v)k_i \mid GCD(x_i, v)(即 kik_i 整除 gcd⁡(xi,v)\gcd(x_i, v)),
    • xi+v≤six_i + v \leq s_i,
    • xi⊕vx_i \oplus v 的值最大(其中 ⊕\oplus 表示异或运算);
      若不存在满足条件的数,则输出 −1-1。

保证第一个任务的类型为 11,且至少存在一个类型为 22 的任务。

输出格式

For each task of type 22, output on one line the desired number vv, or -1 if no such numbers are found.

对于每个类型为 22 的任务,在一行中输出所需的数 vv;若不存在满足条件的数,则输出 −1-1。

输入输出样例

  • 输入#1

    5
    1 1
    1 2
    2 1 1 3
    2 1 1 2
    2 1 1 1

    输出#1

    2
    1
    -1
  • 输入#2

    10
    1 9
    2 9 9 22
    2 3 3 18
    1 25
    2 9 9 20
    2 25 25 14
    1 20
    2 26 26 3
    1 14
    2 20 20 9

    输出#2

    9
    9
    9
    -1
    -1
    -1

说明/提示

In the first example, there are 5 tasks:

  • The first task requires you to add 11 into aa. aa is now \left{1\right}.
  • The second task requires you to add 22 into aa. aa is now \left{1, 2\right}.
  • The third task asks you a question with x=1x = 1, k=1k = 1 and s=3s = 3. Taking both 11 and 22 as vv satisfies 1∣GCD(1,v)1 \mid GCD(1, v) and 1+v≤31 + v \leq 3. Because 2⊕1=3>1⊕1=02 \oplus 1 = 3 \gt 1 \oplus 1 = 0, 22 is the answer to this task.
  • The fourth task asks you a question with x=1x = 1, k=1k = 1 and s=2s = 2. Only v=1v = 1 satisfies 1∣GCD(1,v)1 \mid GCD(1, v) and 1+v≤21 + v \leq 2, so 11 is the answer to this task.
  • The fifth task asks you a question with x=1x = 1, k=1k = 1 and s=1s = 1. There are no elements in aa that satisfy the conditions, so we report -1 as the answer to this task.

在第一个例子中,共有 5 个任务:

  • 第一个任务要求将 11 加入集合 aa 中。此时 a={1}a = \left\{1\right\}。
  • 第二个任务要求将 22 加入集合 aa 中。此时 a={1,2}a = \left\{1, 2\right\}。
  • 第三个任务是一个询问,参数为 x=1x = 1、k=1k = 1 和 s=3s = 3。同时取 v=1v = 1 和 v=2v = 2 均满足条件 1∣GCD(1,v)1 \mid GCD(1, v) 以及 1+v≤31 + v \leq 3。由于 2⊕1=3>1⊕1=02 \oplus 1 = 3 > 1 \oplus 1 = 0,因此该任务的答案为 22。
  • 第四个任务是一个询问,参数为 x=1x = 1、k=1k = 1 和 s=2s = 2。仅 v=1v = 1 满足条件 1∣GCD(1,v)1 \mid GCD(1, v) 以及 1+v≤21 + v \leq 2,因此该任务的答案为 11。
  • 第五个任务是一个询问,参数为 x=1x = 1、k=1k = 1 和 s=1s = 1。集合 aa 中没有任何元素满足条件,因此该任务的答案为 −1-1。

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

首页