CF1168C.And Reachability
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Toad Pimple has an array of integers a1,a2,…,an.
We say that y is reachable from x if x<y and there exists an integer array p such that x=p1<p2<…<pk=y, and api&api+1>0 for all integers i such that 1≤i<k.
Here & denotes the bitwise AND operation.
You are given q pairs of indices, check reachability for each of them.
蟾蜍皮普尔有一个整数数组 a1,a2,…,an。
我们称 y 可从 x 到达,当且仅当 x<y,且存在一个整数数组 p,满足 x=p1<p2<…<pk=y,并且对所有满足 1≤i<k 的整数 i,均有 api&api+1>0。
此处 & 表示按位与运算。
你将收到 q 对下标,请对每一对判断其可达性。
输入格式
The first line contains two integers n and q (2≤n≤300000, 1≤q≤300000) — the number of integers in the array and the number of queries you need to answer.
The second line contains n space-separated integers a1,a2,…,an (0≤ai≤300000) — the given array.
The next q lines contain two integers each. The i-th of them contains two space-separated integers xi and yi (1≤xi<yi≤n). You need to check if yi is reachable from xi.
第一行包含两个整数 n 和 q(2≤n≤300000,1≤q≤300000)—— 分别表示数组中整数的个数以及需要回答的查询个数。
第二行包含 n 个以空格分隔的整数 a1,a2,…,an(0≤ai≤300000)—— 给定的数组。
接下来的 q 行每行包含两个整数。其中第 i 行包含两个以空格分隔的整数 xi 和 yi(1≤xi<yi≤n)。你需要判断 yi 是否可以从 xi 到达。
输出格式
Output q lines. In the i-th of them print "Shi" if yi is reachable from xi, otherwise, print "Fou".
输出 q 行。在第 i 行中,如果从 xi 可以到达 yi,则输出 "Shi";否则,输出 "Fou"。
输入输出样例
输入#1
5 3 1 3 0 2 1 1 3 2 4 1 4
输出#1
Fou Shi Shi
说明/提示
In the first example, a3=0. You can't reach it, because AND with it is always zero. a2&a4>0, so 4 is reachable from 2, and to go from 1 to 4 you can use p=[1,2,4].
在第一个例子中,a3=0。你无法到达它,因为与它进行按位与运算的结果恒为零。a2&a4>0,因此可以从 2 到达 4;而要从 1 到达 4,可以使用路径 p=[1,2,4]。
输入解题思路,AI测评打分。不知道怎么写?