欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1878E.Iva & Pav
Iva & Pav
CF1878E · Iva & Pav
- 难度:1400
- 标签:binary search、bitmasks、data structures、greedy
- 链接:https://codeforces.com/problemset/problem/1878/E
- 时间限制:5 seconds 内存限制:256 megabytes
- 出现位置:Day22-阶段模拟4-S T1-T3综合卷
英文原题面
Statement
Iva and Pav are a famous Serbian competitive programming couple. In Serbia, they call Pav "papuca" and that's why he will make all of Iva's wishes come true. Iva gave Pav an array of elements. Let's define (here denotes the bitwise AND operation). Note that is not defined when . Iva also gave Pav queries. Each query consists of 2 numbers, and , and she wants Pav to find the largest index (), such that . Pav wants to solve this problem fast because he doesn't want to upset Iva. He needs your help.
Input
The first line contains a single integer () — the number of test cases. The first line of each test case contains a single integer () — the length of array . The second line of each test case contains integers () — the elements of array . The third line of each test case contains a single integer () — the number of queries Iva gave Pav. The next lines of each test case contains two numbers, and (, ) — the left bound for the subsegment, and the integer described in statement. It is guaranteed that the sum of over all test cases does not exceed . Also, it is guaranteed that the sum of over all test cases does not exceed .
Output
For each query output maximal index () such that . If such doesn't exist, output .
样例
样例 1
输入:
3
5
15 14 17 42 34
3
1 7
2 15
4 5
5
7 5 3 1 7
4
1 7
5 7
2 3
2 2
7
19 20 15 12 21 7 11
4
1 15
4 4
7 12
5 7
输出:
2 -1 5
1 5 2 2
2 6 -1 5
样例解释(英文原文)
In the first test case , and the array The first query asks for the biggest index such that the . $f(1,1) = 15, \ f(1, 2) = 14, \ f(1,3)=0 \ f(1, 4)=0 \ f(1, 5)=0$, so is the answer. The second query asks for . Since such doesn't exist, the answer is . The third query asks for . , so is the answer. In the second test case , and the array . For the first query, . $f(1, 1)=7, \ f(1, 2)=5, \ f(1, 3) = 1, \ f(1,4) = 1, \ f(1, 5)=1$, so the answer to this query is . For the second query, . , so the answer is . For the third query, . $f(2, 2) = 5, \ f(2, 3) = 1, \ f(2, 4) = 1, \ f(2, 5) = 1$, so the answer is .
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |