CF1148F.Foo Fighters
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n objects. Each object has two integer properties: vali — its price — and maski. It is guaranteed that the sum of all prices is initially non-zero.
You want to select a positive integer s. All objects will be modified after that. The i-th object will be modified using the following procedure:
- Consider maski and s in binary notation,
- Compute the bitwise AND of s and maski (s&maski),
- If (s&maski) contains an odd number of ones, replace the vali with −vali. Otherwise do nothing with the i-th object.
You need to find such an integer s 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.
你有 n 个物体。每个物体有两个整数属性:vali(其价格)和 maski。保证所有价格的初始总和非零。
你需要选择一个正整数 s。随后,所有物体都将被修改。第 i 个物体将按如下步骤修改:
- 将 maski 和 s 表示为二进制形式;
- 计算 s 与 maski 的按位与(即 s&maski);
- 若 s&maski 的二进制表示中包含奇数个 1,则将 vali 替换为 −vali;否则不对第 i 个物体作任何改动。
你需要找出一个整数 s,使得上述修改完成后,所有价格之和变号(若原和为负,则变为正;若原和为正,则变为负;不允许总和变为零)。总和的绝对值可为任意值。
输入格式
The first line contains a single integer n (1≤n≤3⋅105) — the number of objects.
The i-th of next n lines contains integers vali and maski (−109≤vali≤109, 1≤maski≤262−1) — the price of the object and its mask.
It is guaranteed that the sum of vali is initially non-zero.
第一行包含一个整数 n(1≤n≤3⋅105)—— 表示物体的数量。
接下来的 n 行中,第 i 行包含两个整数 vali 和 maski(−109≤vali≤109,1≤maski≤262−1)—— 分别表示该物体的价格及其掩码。
保证所有 vali 的初始总和非零。
输出格式
Print an integer s (1≤s≤262−1), such that if we modify the objects as described above, the sign of the sum of vali changes its sign.
If there are multiple such s, print any of them. One can show that there is always at least one valid s.
输出一个整数 s(1≤s≤262−1),使得按照上述描述修改对象后,vali 的总和的符号发生改变。
如果存在多个满足条件的 s,输出任意一个即可。可以证明,至少存在一个合法的 s。
输入输出样例
输入#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 151.
So their total sum will change its sign: initially 24, after modifications — −28.
In the second test sample the only object will change its price. So the total sum will change its sign.
在第一个测试样例中,所有物品的价格都会发生变化,除了掩码为 151 的物品。
因此,它们的总和将改变符号:初始为 24,修改后为 −28。
在第二个测试样例中,唯一的一个物品的价格将发生变化。因此,总和将改变符号。
输入解题思路,AI测评打分。不知道怎么写?