QOJ.ac

QOJ

Límite de tiempo: 9 s Límite de memoria: 512 MB Puntuación total: 100

#4625. 简单数学 4

Estadísticas

给定非负整数 $N, L, R$ 和 $X$,求满足以下条件的长度为 $N$ 的整数数组 $A$ 中,$\sum_{i=1}^N A_i$ 的最大值:

  • $\bigoplus_{i=1}^N A_i = X$,其中 $\oplus$ 表示异或运算。
  • $\forall 1 \le i \le N, L \le A_i \le R$。

如果不存在满足上述要求的有效数组 $A$,输出 $-1$。

第一行包含一个整数 $T$ ($1 \le T \le 3000$),表示测试用例的数量。 对于每个测试用例,包含一行整数 $N, L, R, X$ ($1 \le N \le 10^9, 0 \le L \le R \le 10^9, 0 \le X \le 10^9$)。

对于每个测试用例,输出一行一个整数,表示答案。

样例

输入格式 1

1
5 890 970 768

输出格式 1

4756

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.