hdu6287(思维)

博客围绕hdu6287展开,涉及思维相关内容,但因内容缺失,具体关键信息不明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
vector<int> G[maxn];
int T;
int n, m;


void process(int x, int loc)
{
    int t = (int)sqrt(x);
    for(int i = 2; i <= t; i++)
    {
        while(x % i == 0)
        {
            G[i].push_back(loc);
            x /= i;
        }
    }
    if(x > 1)
        G[x].push_back(loc);
}

int main()
{
    cin >> T;
    while(T--)
    {
        for(int i = 1; i < maxn; i++)
            G[i].clear();

        cin >> n >> m;
        int t;
        for(int i = 1; i <= n; i++)
        {
            scanf("%d", &t);
            process(t, i);
        }
        int l, r, x;
        for(int i = 1; i <= m; i++)
        {
            scanf("%d%d%d", &l, &r, &x);
            int tt = (int)sqrt(x);
            int cnt;
            bool flag = true;
            for(int j = 2; j <= tt; j++)
            {
                cnt = 0;
                while(x % j == 0)
                {
                    cnt++;
                    x /= j;
                }
                if(!cnt)    continue;        //每次边拆分边判断,就不需要再开数组存查询的质因数分解并比较,简便。
                //int dif = upper_bound(G[j].begin(), G[j].end(), r) - pos - (lower_bound(G[j].begin(), G[j].end(), l) - pos);  完整理解,-pos + pos抵消
                int dif = upper_bound(G[j].begin(), G[j].end(), r) - lower_bound(G[j].begin(), G[j].end(), l);
                if(dif < cnt)
                {
                    flag = false;
                    break;
                }
            }
            if(x > 1)        //注意千万记得特判 > sqrt(x)的质因数,坑点!
            {
                int dif = upper_bound(G[x].begin(), G[x].end(), r) - lower_bound(G[x].begin(), G[x].end(), l);
                if(dif < 1)
                {
                    flag = false;
                }
            }
            if(flag)
                printf("Yes\n");
            else
                printf("No\n");
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值