# hdu 6287 口算训练(二分)

Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 3024 Accepted Submission(s): 660

Problem Description

Input

Output

Sample Input
1
5 4
6 4 7 2 5
1 2 24
1 3 18
2 5 17
3 5 35

Sample Output
Yes
No
No
Yes

Source
"字节跳动杯"2018中国大学生程序设计竞赛-女生专场

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<vector>
using namespace std;
const int N = 1e5+10;
const int M = 500000;
typedef long long LL;
const LL mod = 20180520;
const int maxt=1000000000;
vector<int>q[N];
int p[N], vis[N];

int main()
{
memset(vis,0,sizeof(vis));
int num=0;
for(int i=2; i<=N; i++)
{
if(vis[i])continue;
p[num++]=i;
for(int j=i*2; j<=N; j+=i)vis[j]=1;
}
int t;
scanf("%d", &t);
while(t--)
{
int n, m, k;
scanf("%d %d", &n, &m);
for(int i=0; i<N; i++)
{
q[i].clear();
q[i].push_back(0);
}

for(int i=1; i<=n; i++)
{
int x;
scanf("%d", &x);
for(int j=0;p[j]*p[j]<=x; j++)
{
if(x%p[j]!=0)continue;
while( x%p[j]==0)
{
x/=p[j];
q[p[j]].push_back(i);
}
}
if(x>1)q[x].push_back(i);
}
for(int i=1; i<=m; i++)
{
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
int flag=0, al, ar;
for(int j=0;p[j]*p[j]<=x; j++)
{
if(x==1)break;
if(x%p[j]!=0)continue;
int cnt=0;
while(x!=1 && x%p[j]==0)
{
cnt++;
x/=p[j];
}
al=lower_bound(q[p[j]].begin(),q[p[j]].end(),l)-q[p[j]].begin();
ar=upper_bound(q[p[j]].begin(),q[p[j]].end(),r)-q[p[j]].begin();
if(ar-al<cnt)
{
flag=1;
break;
}
}
if(x>1)
{
al=lower_bound(q[x].begin(),q[x].end(),l)-q[x].begin();
ar=upper_bound(q[x].begin(),q[x].end(),r)-q[x].begin();
if(ar-al<=0)flag=1;
}
if(flag==0)printf("Yes\n");
else printf("No\n");
}
}
return 0;
}