E. And Reachability
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Toad Pimple has an array of integers a1,a2,…,an.

We say that 1≤i<k.

Here bitwise AND operation.

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

Input

The first line contains two integers 1≤q≤300000) — the number of integers in the array and the number of queries you need to answer.

The second line contains 0≤ai≤300000) — the given array.

The next xi.

Output

Output 

Example
input
Copy
5 3
1 3 0 2 1
1 3
2 4
1 4
output
Copy
Fou
Shi
Shi
Note

In the first example, p=[1,2,4].

#include<iostream>
#include<cstdio>
#define maxn 300010
using namespace std;
int n,q,a[maxn],dp[maxn][30],las[30];
int main(){
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=0;i<20;i++){
        las[i]=n+1;
        dp[n+1][i]=n+1;
    }
    for(int i=n;i>=1;i--){
        for(int j=0;j<20;j++)
            dp[i][j]=n+1;
        for(int j=0;j<20;j++){
            if(a[i]&(1<<j)){
                for(int k=0;k<20;k++)
                    dp[i][k]=min(dp[i][k],dp[las[j]][k]);
                las[j]=i;
                dp[i][j]=i;
            }
        }
    }
    int x,y;
    while(q--){
        cin>>x>>y;
        bool f=0;
        for(int i=0;i<20;i++){
            if(a[y]&(1<<i)&&dp[x][i]<=y){
                f=1;
                break;
            }
        }
        if(f)puts("Shi");
        else puts("Fou");
    }
    return 0;
}

 

相关文章:

  • 2021-09-08
  • 2021-11-28
  • 2021-11-25
  • 2022-02-28
  • 2021-10-08
  • 2021-12-13
  • 2021-12-22
猜你喜欢
  • 2022-12-23
  • 2021-12-12
  • 2021-08-12
  • 2021-07-13
  • 2022-03-04
  • 2021-05-22
  • 2021-08-09
相关资源
相似解决方案