CF1148F.Foo Fighters

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given nn objects. Each object has two integer properties: valival_i — its price — and maskimask_i. It is guaranteed that the sum of all prices is initially non-zero.

You want to select a positive integer ss. All objects will be modified after that. The ii-th object will be modified using the following procedure:

  • Consider maskimask_i and ss in binary notation,
  • Compute the bitwise AND of ss and maskimask_i (s & maskis \,\&\, mask_i),
  • If (s & maskis \,\&\, mask_i) contains an odd number of ones, replace the valival_i with −vali-val_i. Otherwise do nothing with the ii-th object.

You need to find such an integer ss that when the modification above is done the sum of all prices changes sign (if it was negative, it should become positive, and vice-versa; it is not allowed for it to become zero). The absolute value of the sum can be arbitrary.

你有 nn 个物体。每个物体有两个整数属性:valival_i(其价格)和 maskimask_i。保证所有价格的初始总和非零。

你需要选择一个正整数 ss。随后,所有物体都将被修改。第 ii 个物体将按如下步骤修改:

  • 将 maskimask_i 和 ss 表示为二进制形式;
  • 计算 ss 与 maskimask_i 的按位与(即 s & maskis \,\&\, mask_i);
  • 若 s & maskis \,\&\, mask_i 的二进制表示中包含奇数个 11,则将 valival_i 替换为 −vali-val_i;否则不对第 ii 个物体作任何改动。

你需要找出一个整数 ss,使得上述修改完成后,所有价格之和变号(若原和为负,则变为正;若原和为正,则变为负;不允许总和变为零)。总和的绝对值可为任意值。

输入格式

The first line contains a single integer nn (1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5) — the number of objects.

The ii-th of next nn lines contains integers valival_i and maskimask_i (−109≤vali≤109-10^9 \leq val_i \leq 10^9, 1≤maski≤262−11 \le mask_i \le 2^{62} - 1) — the price of the object and its mask.

It is guaranteed that the sum of valival_i is initially non-zero.

第一行包含一个整数 nn(1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5)—— 表示物体的数量。

接下来的 nn 行中,第 ii 行包含两个整数 valival_i 和 maskimask_i(−109≤vali≤109-10^9 \leq val_i \leq 10^9,1≤maski≤262−11 \le mask_i \le 2^{62} - 1)—— 分别表示该物体的价格及其掩码。

保证所有 valival_i 的初始总和非零。

输出格式

Print an integer ss (1≤s≤262−11 \le s \le 2^{62} - 1), such that if we modify the objects as described above, the sign of the sum of valival_i changes its sign.

If there are multiple such ss, print any of them. One can show that there is always at least one valid ss.

输出一个整数 ss(1≤s≤262−11 \le s \le 2^{62} - 1),使得按照上述描述修改对象后,valival_i 的总和的符号发生改变。

如果存在多个满足条件的 ss,输出任意一个即可。可以证明,至少存在一个合法的 ss。

输入输出样例

  • 输入#1

    5
    17 206
    -6 117
    -2 151
    9 93
    6 117

    输出#1

    64
  • 输入#2

    1
    1 1

    输出#2

    1

说明/提示

In the first test sample all objects will change their prices except for the object with mask 151151.

So their total sum will change its sign: initially 2424, after modifications — −28-28.

In the second test sample the only object will change its price. So the total sum will change its sign.

在第一个测试样例中,所有物品的价格都会发生变化,除了掩码为 151151 的物品。

因此,它们的总和将改变符号:初始为 2424,修改后为 −28-28。

在第二个测试样例中,唯一的一个物品的价格将发生变化。因此,总和将改变符号。

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

首页