CF1168C.And Reachability

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Toad Pimple has an array of integers a1,a2,…,ana_1, a_2, \ldots, a_n.

We say that yy is reachable from xx if x<yx \lt y and there exists an integer array pp such that x=p1<p2<…<pk=yx = p_1 \lt p_2 \lt \ldots \lt p_k=y, and api & api+1>0a_{p_i}\, \&\, a_{p_{i+1}} \gt 0 for all integers ii such that 1≤i<k1 \leq i \lt k.

Here &\& denotes the bitwise AND operation.

You are given qq pairs of indices, check reachability for each of them.

蟾蜍皮普尔有一个整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n。

我们称 yy 可从 xx 到达,当且仅当 x<yx \lt y,且存在一个整数数组 pp,满足 x=p1<p2<…<pk=yx = p_1 \lt p_2 \lt \ldots \lt p_k=y,并且对所有满足 1≤i<k1 \leq i \lt k 的整数 ii,均有 api & api+1>0a_{p_i}\, \&\, a_{p_{i+1}} \gt 0。

此处 &\& 表示按位与运算。

你将收到 qq 对下标,请对每一对判断其可达性。

输入格式

The first line contains two integers nn and qq (2≤n≤300 0002 \leq n \leq 300\,000, 1≤q≤300 0001 \leq q \leq 300\,000) — the number of integers in the array and the number of queries you need to answer.

The second line contains nn space-separated integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤300 0000 \leq a_i \leq 300\,000) — the given array.

The next qq lines contain two integers each. The ii-th of them contains two space-separated integers xix_i and yiy_i (1≤xi<yi≤n1 \leq x_i \lt y_i \leq n). You need to check if yiy_i is reachable from xix_i.

第一行包含两个整数 nn 和 qq(2≤n≤300 0002 \leq n \leq 300\,000,1≤q≤300 0001 \leq q \leq 300\,000)—— 分别表示数组中整数的个数以及需要回答的查询个数。

第二行包含 nn 个以空格分隔的整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤300 0000 \leq a_i \leq 300\,000)—— 给定的数组。

接下来的 qq 行每行包含两个整数。其中第 ii 行包含两个以空格分隔的整数 xix_i 和 yiy_i(1≤xi<yi≤n1 \leq x_i \lt y_i \leq n)。你需要判断 yiy_i 是否可以从 xix_i 到达。

输出格式

Output qq lines. In the ii-th of them print "Shi" if yiy_i is reachable from xix_i, otherwise, print "Fou".

输出 qq 行。在第 ii 行中,如果从 xix_i 可以到达 yiy_i,则输出 "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=0a_3 = 0. You can't reach it, because AND with it is always zero. a2 & a4>0a_2\, \&\, a_4 \gt 0, so 44 is reachable from 22, and to go from 11 to 44 you can use p=[1,2,4]p = [1, 2, 4].

在第一个例子中,a3=0a_3 = 0。你无法到达它,因为与它进行按位与运算的结果恒为零。a2 & a4>0a_2\, \&\, a_4 \gt 0,因此可以从 22 到达 44;而要从 11 到达 44,可以使用路径 p=[1,2,4]p = [1, 2, 4]。

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

首页