/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 1008.0 KiB
#2 Accepted 3ms 1.051 MiB
#3 Accepted 54ms 1.191 MiB
#4 Accepted 54ms 1.234 MiB
#5 Accepted 65ms 1.199 MiB
#6 Accepted 63ms 1.34 MiB
#7 Accepted 73ms 2.312 MiB
#8 Accepted 87ms 2.68 MiB
#9 Accepted 76ms 2.379 MiB
#10 Accepted 116ms 10.543 MiB
#11 Accepted 91ms 9.148 MiB
#12 Accepted 99ms 9.172 MiB
#13 Accepted 80ms 2.594 MiB
#14 Accepted 70ms 2.461 MiB
#15 Accepted 66ms 1.191 MiB
#16 Accepted 66ms 1.273 MiB
#17 Accepted 49ms 1.145 MiB
#18 Accepted 64ms 1.285 MiB
#19 Accepted 67ms 1.309 MiB
#20 Accepted 88ms 2.676 MiB
#21 Accepted 130ms 13.684 MiB
#22 Accepted 136ms 13.734 MiB
#23 Accepted 116ms 7.371 MiB
#24 Accepted 114ms 18.078 MiB
#25 Accepted 58ms 7.18 MiB
#26 Accepted 84ms 1.266 MiB
#27 Accepted 111ms 7.73 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
bool ar[200004];
vector<ll>p;
void seive()
{
    ll mxN=200000;
    for(int i=0;i<=mxN;i++)
        ar[i]=true;
    ar[0]=ar[1]=false;
    for(int i=2;i*i<=mxN;i++)
    {
        if(ar[i]==true)
        {
            for(int j=i*i;j<=mxN;j+=i)
            {
                ar[j]=false;
            }
        }
    }
    for(int i=1;i<=mxN;i++)
    {
        if(ar[i]==true)
            p.push_back(i);
    }


}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  seive();
    ll tc;
    cin>>tc;
    while(tc--)
    {
        ll n,x;
        cin>>n>>x;
        map<ll,ll>mp;
        ll u=x;
        vector<ll>v(n);
        for(int i=0;i<p.size() && p[i]*p[i]<=u;i++)
        {
            if(u%p[i]==0)
            {
                while(u%p[i]==0)
                {
                    mp[p[i]]++;
                    u/=p[i];
                }
            }
        }
        if(u>1)
            mp[u]++;
        vector<ll>ar;
        for(auto it:mp)
            ar.push_back(it.first);
        vector<ll>br[n+1];
        for(int i=0;i<n;i++)
        {
            cin>>v[i];
            ll x=v[i];
            ll c=0;
            if(i==0){
            for(int j=0;j<ar.size();j++)
            {
                br[i].push_back(0);

            }
                
                for(int j=0;j<ar.size();j++)
                {
                    c=0;
                    if(x%ar[j]==0)
                    {
                        
                        while(x%ar[j]==0)
                        {
                            c++;
                            x/=ar[j];
                        }
                        
                    }
                    br[i][j]+=c;
                }
                if(x>1 && mp[x]>1)
                {
                    for(int j=0;j<ar.size();j++)
                    {
                        if(ar[j]==x)
                            br[i][j]++;
                    }
                }
                
            }
            else
            {
                for(int j=0;j<ar.size();j++)
            {
                br[i].push_back(0);

            }
                
                for(int j=0;j<ar.size();j++)
                {
                    c=0;
                    if(x%ar[j]==0)
                    {
                        
                        while(x%ar[j]==0)
                        {
                            c++;
                            x/=ar[j];
                        }
                        
                    }
                    br[i][j]=(br[i-1][j]+c);
                }
                if(x>1 && mp[x]>1)
                {
                    for(int j=0;j<ar.size();j++)
                    {
                        if(ar[j]==x)
                            br[i][j]++;
                    }
                }
            }
        }
        ll q;
        cin>>q;
        while(q--)
        {
            ll l,r;
            cin>>l>>r;
            l--;
            r--;
            if(l==0)
            {
                ll c=0;
                for(int j=0;j<ar.size();j++)
                {
                    if(br[r][j]<mp[ar[j]])
                    {
                        c=1;
                        break;
                    }
                }
                if(c==1)
                    cout<<"No\n";
                else
                    cout<<"Yes\n";
            }
            else
            {
                   ll c=0;
                for(int j=0;j<ar.size();j++)
                {
                    if((br[r][j]-br[l-1][j])<mp[ar[j]])
                    {
                        c=1;
                        break;
                    }
                }
                if(c==1)
                    cout<<"No\n";
                else
                    cout<<"Yes\n";
            }
        }
        
    }
        

}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Contest
Brain Booster #7
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 15:58:25
Judged At
2024-11-11 02:29:01
Judged By
Score
100
Total Time
136ms
Peak Memory
18.078 MiB