题目链接
题解
太(sb)了,这种题都想不出来
发现复杂度允许(nsqrt{n}),我们可以对于每个位置(sqrt{n})枚举约数,然后维护比例的最晚出现的位置,维护每种数出现的最晚位置
询问按(r)排序,在维护的同时回答询问,只需看该比例最晚位置是否在(l)右侧即可
这样做事默认(a[y])在(a[x])左边,反过来再做一次即可
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
int n,m,A[maxn],f[maxn],g[maxn],ans[maxn];
struct Que{int l,r,b,id;}q[maxn];
inline bool operator <(const Que& a,const Que& b){
return a.r < b.r;
}
void work(){
sort(q + 1,q + 1 + m);
cls(f); cls(g);
int pos = 1;
for (int i = 1; i <= n; i++){
for (int j = 1; j * j <= A[i]; j++)
if (A[i] % j == 0){
g[j] = max(g[j],f[A[i] / j]);
g[A[i] / j] = max(g[A[i] / j],f[j]);
}
f[A[i]] = i;
while (pos <= m && q[pos].r <= i){
ans[q[pos].id] |= (g[q[pos].b] >= q[pos].l);
pos++;
}
}
}
int main(){
n = read(); m = read();
REP(i,n) A[i] = read();
REP(i,m) q[i].id = i,q[i].l = read(),q[i].r = read(),q[i].b = read();
work();
reverse(A + 1,A + 1 + n);
REP(i,m) q[i].l = (n - q[i].l + 1),q[i].r = (n - q[i].r + 1),swap(q[i].l,q[i].r);
work();
REP(i,m) puts(ans[i] ? "Yes" : "No");
return 0;
}