/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 1.02 MiB
#2 Accepted 3ms 1.02 MiB
#3 Accepted 51ms 1.074 MiB
#4 Accepted 76ms 1.191 MiB
#5 Accepted 58ms 1.145 MiB
#6 Accepted 59ms 1.293 MiB
#7 Accepted 92ms 2.277 MiB
#8 Accepted 104ms 2.715 MiB
#9 Accepted 88ms 2.344 MiB
#10 Accepted 85ms 10.641 MiB
#11 Accepted 75ms 9.141 MiB
#12 Accepted 76ms 9.145 MiB
#13 Accepted 71ms 2.645 MiB
#14 Accepted 60ms 2.395 MiB
#15 Accepted 59ms 1.266 MiB
#16 Accepted 60ms 1.145 MiB
#17 Accepted 44ms 1.145 MiB
#18 Accepted 69ms 1.188 MiB
#19 Accepted 69ms 1.316 MiB
#20 Accepted 93ms 2.617 MiB
#21 Accepted 130ms 13.715 MiB
#22 Accepted 109ms 13.645 MiB
#23 Accepted 99ms 7.363 MiB
#24 Accepted 107ms 17.895 MiB
#25 Accepted 47ms 7.27 MiB
#26 Accepted 77ms 1.262 MiB
#27 Accepted 105ms 7.605 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-05 15:58:25
Judged By
Score
100
Total Time
130ms
Peak Memory
17.895 MiB