/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 6ms 1.285 MiB
#2 Accepted 7ms 1.18 MiB
#3 Accepted 184ms 1.352 MiB
#4 Accepted 201ms 1.387 MiB
#5 Accepted 228ms 1.422 MiB
#6 Accepted 239ms 1.445 MiB
#7 Accepted 245ms 2.207 MiB
#8 Accepted 294ms 2.297 MiB
#9 Accepted 276ms 2.328 MiB
#10 Accepted 302ms 6.637 MiB
#11 Accepted 234ms 6.613 MiB
#12 Accepted 242ms 6.621 MiB
#13 Accepted 253ms 2.402 MiB
#14 Accepted 202ms 1.77 MiB
#15 Accepted 200ms 1.375 MiB
#16 Accepted 206ms 1.367 MiB
#17 Accepted 188ms 1.273 MiB
#18 Accepted 586ms 1.379 MiB
#19 Accepted 643ms 1.547 MiB
#20 Accepted 728ms 3.316 MiB
#21 Accepted 901ms 10.059 MiB
#22 Accepted 866ms 9.887 MiB
#23 Accepted 133ms 2.949 MiB
#24 Accepted 559ms 10.496 MiB
#25 Time Exceeded ≥1573ms ≥2.496 MiB
#26 Accepted 566ms 1.344 MiB
#27 Time Exceeded ≥1566ms ≥2.48 MiB

Code



#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl "\n"
#define FF ios_base::sync_with_stdio(0);cin.tie(0)
#define binary(value, size) cout << bitset<size>(value) << '\n'
#define Tp template<class T>
#define Tpp template<typename T>
#define Tppp template<typename T1,typename T2>
#define eps 1e-9
#define pf printf
#define sf scanf
#define clr(arr,val) memset((arr),val,(sizeof(arr)))
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define repb(i,a,b) for(long long int i=a;i>=b;i--)
#define all(v) (v).begin(),(v).end()
#define asort(a) sort(a.begin(),a.end())
#define arev(a) reverse(a.begin(),a.end())
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pbb pop_back
#define mp make_pair
#define V vector
#define P pair
#define M map
#define mt make_tuple
#define BS(v,x) binary_search(v.begin(),v.end(),x) //return true /false
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()//found and that value and not found than greater value pos
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin() //found and greater value pos && not found also greater pos
#define sma(c) towlower(c)
#define rt(x) sqrt(x)
#define cap(c) towupper(c)
#define sq(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define SUM(v) accumulate (v.begin(),v.end(),0)//sum of the vector
#define MAX(v) *max_element(v.begin(),v.end())//max element of the vector
#define MIN(v) *min_element(v.begin(),v.end())//min element of the vector
#define SZ(x) long long int(x.size())
#define Ceil(n) (long long int)ceil(n)
#define Floor(n) (long long int)floor(n)
#define deb(x) cout << #x << " = " << x << "\n";
#define deb2(x,y)  cout << #x << " = " << x << ", "; cout << #y << " = " << y << "\n";
#define deb3(x,y,z) cout << #x << " = " << x << ", "; cout << #y << " = " << y << ", "; cout << #z << " = " << z << "\n";
#define deb4(x,y,z,r) cout << #x << " = " << x << ", "; cout << #y << " = " << y << ", "; cout << #z << " = " << z << ", ";cout << #r << " = " << r << "\n";
#define out(ans) cout<<ans<<"\n"
#define outs(ans) cout<<ans<<" "<<"\n"
#define FI freopen ("in.txt", "r", stdin)
#define FO freopen ("out.txt", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;

typedef int ll;
typedef double lf;
typedef long double llf;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll> > v2d;
typedef vector<vector<vector<ll> > > v3d;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef map<ll,ll> mpl;
typedef priority_queue<ll> heap;// heap max value from top
typedef priority_queue<ll, vector<ll>, greater<ll> > revheap;//heap min value from top

bool Check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}
int Set(int N,int pos)
{
    return N=N | (1<<pos);
}

const int mx=1e6+10;
int status[(mx/32)+2];
ll N=mx;
vll primes;
void sieve()
{

	 memset(status,0,sizeof(status));
	 int i, j, sqrtN;
     sqrtN = int( sqrt( N ) );
     for( i = 3; i <= sqrtN; i += 2 )
     {
		 if( Check(status[i>>5],i&31)==0)
		 {
	 		 for(j = i*i; j <= N; j += (i<<1) )
			 {
				 status[j>>5]=Set(status[j>>5],j & 31)   ;
	 		 }
		 }
	 }
	 primes.pb(2);

	 for(i=3;i<=N;i+=2)
        if( Check(status[i>>5],i&31)==0) primes.pb(i);
     //deb(primes.size());
}


map<ll,vll>mm,vali;

void factorize(ll idx,ll n )
{

    //vll factors;
    ll sqrtn = sqrt ( n );
    ll r=primes.size();
    //deb(n);
    for ( ll i = 0; i <r  && primes[i] <= sqrtn; i++ )
    {
        if ( n % primes[i] == 0 )
        {
            ll xg=0;
            while ( n % primes[i] == 0 )
            {
                xg++;
                n /= primes[i];
                //freq[primes[i]]++;
            }
            ll pp=vali[primes[i]].size();
            ll last;
            if(pp==0) last=0;
            else last=vali[primes[i]][pp-1];

            vali[primes[i]].pb(last+xg);
            mm[primes[i]].pb(idx);
            //deb2(primes[i],xg);
            //factors.pb(primes[i]);
            sqrtn = sqrt ( n );
        }
    }
    if ( n != 1 )
    {
         ll pp=vali[n].size();
         ll last;
         if(pp==0) last=0;
         else last=vali[n][pp-1];
         mm[n].pb(idx);
         vali[n].pb(last+1);
    }
//    ll q=factors.size();
//    for(ll i=0;i<q;i++)
//    {
//        if(i!=q-1)cout<<factors[i]<<"^"<<freq[factors[i]]<<" ";
//        else cout<<factors[i]<<"^"<<freq[factors[i]];
//    }
//    cout<<endl;
}
vpll temp;
void factorize2(ll n)
{

    //vll factors;
    //vpll temp;
    ll sqrtn = sqrt ( n );
    ll r=primes.size();
    for ( ll i = 0; i <r  && primes[i] <= sqrtn; i++ )
    {
        if ( n % primes[i] == 0 )
        {            ll xx=0;
            while ( n % primes[i] == 0 )
            {
                xx++;
                n /= primes[i];
                //freq[primes[i]]++;
            }
            temp.pb({primes[i],xx});
            //temp[{primes[i],xx}].pb(i);
            //factors.pb(primes[i]);
            sqrtn = sqrt ( n );
        }
    }
    if ( n != 1 )
    {
        temp.pb({n,1});
    }
    //return temp;
//    ll q=factors.size();
//    for(ll i=0;i<q;i++)
//    {
//        if(i!=q-1)cout<<factors[i]<<"^"<<freq[factors[i]]<<" ";
//        else cout<<factors[i]<<"^"<<freq[factors[i]];
//    }
//    cout<<endl;
}

void S()
{
   mm.clear();
   vali.clear();
   temp.clear();
   ll n,x;cin>>n>>x;
   vll v(n);
   rep(i,0,n)
   {
       cin>>v[i];factorize(i,v[i]);
   }
   //return;
   ll q;cin>>q;
   factorize2(x);
   //return;
   //return;
   rep(i,0,q)
   {
       ll left,right;cin>>left>>right;
       left--;right--;
       //return;
       bool ff=1;
       for(auto xx:temp)
       {
           //deb2(xx.F,xx.S);
           //return;
           auto it=lower_bound(all(mm[xx.F]),left);
           auto it2=upper_bound(all(mm[xx.F]),right);
           if(it2==mm[xx.F].begin())
           {
               ff=0;break;
           }


           ll baad=0;

           if(it==mm[xx.F].begin())
           {
               baad=0;
           }
           else
           {
               it--;
               ll pos=it-mm[xx.F].begin();
               baad=vali[xx.F][pos];
           }
           it2--;
           ll ase;
           ll pos2=it2-mm[xx.F].begin();
           if(pos2>=0) ase=vali[xx.F][pos2]-baad;
           else
           {
               ff=0;break;
           }
           //deb(pos);
           if(ase<xx.S)
           {
               ff=0;break;
           }
       }
       if(ff) cout<<"Yes\n";
       else cout<<"No\n";

   }

}

int main()
{
    FF;
    sieve();
    ll tc;cin>>tc;
    while(tc--)
    {
        S();
    }
    return 0;
}


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 16:08:06
Judged At
2024-11-11 02:28:23
Judged By
Score
95
Total Time
≥1573ms
Peak Memory
≥10.496 MiB