/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 2ms 568.0 KiB
#2 Wrong Answer 1ms 324.0 KiB

Code

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> 
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define MOD1 998244353
#define INF 1e18
#define endl "\n"
#define pb push_back
#define ppb pop_back
#define PI 3.141592653589793238462
#define all(a) a.begin(), a.end()
#define read(v,n) for(int i=0;i<n;i++)cin>>v[i]
#define TIN ll t=0;cin>>t;for(int i=0;i<t;i++)
#define no() cout << "NO" << endl
#define yes() cout << "YES" << endl
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
 
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

map<ll,ll> prime_factors(ll num){
    map<ll,ll> factors;
    for(ll i=2;i*i<=num;i++){
        while(num%i==0){
            num/=i;
            factors[i]++;
        }
    }
    if(num>1){
        factors[num]++;
    }
    return factors;
}

struct SegmentTree{
    vector<map<ll,ll>>tree;
    ll n;

    SegmentTree(ll size){
        n=size;
        tree.resize(4*n);
    }

    void build(vector<ll> v,ll node,ll left,ll right){
        if(left==right){
            tree[node]=prime_factors(v[left]);
        }
        else{
            ll mid=(left+right)/2;
            build(v,2*node,left,mid);
            build(v,2*node+1,mid+1,right);
            merge(node);
        }
    }

    void merge(ll node){
        tree[node].clear();
        for(auto factors:tree[2*node]){
            tree[node][factors.first]+=factors.second;
        }
        for(auto factors:tree[2*node+1]){
            tree[node][factors.first]+=factors.second;
        }
    }

    map<ll,ll> query(ll node,ll start,ll end,ll left,ll right){
        if(right<start || left>end){
            return {};
        }
        if(left<=start && right>=end){
            return tree[node];
        }
        ll mid=(start+end)/2;
        map<ll,ll> leftfac=query(2*node,start,mid,left,right);
        map<ll,ll> rightfac=query(2*node+1,mid+1,end,left,right);

        for(auto factors:rightfac){
            leftfac[factors.first]+=factors.second;
        }

        return leftfac;
    }

    void build(vector<ll> v){
        build(v,1,0,n-1);
    }

    map<ll,ll> query(ll l,ll r){
        return query(1,0,n-1,l,r);
    }

};

bool is_divisible(map<ll,ll> mp1,map<ll,ll>mp2){
    for(auto it:mp2){
        if(mp1[it.first]<it.second){
            return false;
        }
    }
    return true;
}

int main(){
    fastio();
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt","w",stdout);
    #endif
    TIN{
        //cout<<"Case #"<<i+1<<":";
        ll n,x,q;
        cin>>n>>x;
        vector<ll> v(n);
        read(v,n);
        map<ll,ll>mp=prime_factors(x);
        cin>>q;
        SegmentTree segtree(n);
        segtree.build(v);
        for(int i=0;i<q;i++){
            ll a,b;
            cin>>a>>b;
            a--;
            b--;
            map<ll,ll> range_fac=segtree.query(a,b);
            if(is_divisible(range_fac,mp)){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
        }
    }
    #ifndef ONLINE_JUDGE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-07 20:00:47
Judged At
2024-11-11 02:23:00
Judged By
Score
0
Total Time
2ms
Peak Memory
568.0 KiB