/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 584.0 KiB
#2 Accepted 4ms 584.0 KiB
#3 Accepted 232ms 1.039 MiB
#4 Accepted 232ms 1.023 MiB
#5 Accepted 261ms 1.047 MiB
#6 Accepted 257ms 1008.0 KiB
#7 Accepted 272ms 1.074 MiB
#8 Accepted 304ms 1.254 MiB
#9 Accepted 298ms 1.129 MiB
#10 Accepted 293ms 2.57 MiB
#11 Accepted 275ms 1.852 MiB
#12 Accepted 280ms 2.18 MiB
#13 Accepted 276ms 1.145 MiB
#14 Accepted 253ms 1.16 MiB
#15 Accepted 275ms 1.004 MiB
#16 Accepted 276ms 1.031 MiB
#17 Accepted 231ms 1.297 MiB
#18 Accepted 726ms 1.039 MiB
#19 Accepted 756ms 1.012 MiB
#20 Accepted 781ms 1.168 MiB
#21 Accepted 855ms 3.438 MiB
#22 Accepted 837ms 3.336 MiB
#23 Accepted 237ms 1.891 MiB
#24 Accepted 360ms 4.961 MiB
#25 Time Exceeded ≥1571ms ≥1.309 MiB
#26 Accepted 757ms 1.043 MiB
#27 Time Exceeded ≥1541ms ≥1.32 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;
const int sz = 1e5 + 5 ;
bool notPrime[sz] ;
int n , x , q , l , r , a;
map<int, vector<int>> prefixSum;
map < int , int > mp ,  Xprime;
vector< int > prime ;
void seive()
{
    for(int  i = 4 ; i < sz ; i += 2) notPrime[i] = 1 ;
    int k = sqrt(sz);
    for(int i = 3 ; i < k ; i += 2)
    {
        for(int j = i*i ; j < sz ; j += i) notPrime[j] = 1 ;
    }
    prime.pb(2) ;
    for(int i = 3  ; i < sz ; i += 2) if(!notPrime[i]) prime.pb(i) ;
}
void primefactor(int X, bool ok)
{
    for(int i = 0; prime[i] <= sqrt(X) && i < prime.size(); i++)
    {
        int cnt = 0 ;
        if(X % prime[i] == 0)
        {
            while(X % prime[i] == 0) X /= prime[i] , cnt++;
            if(ok) Xprime[prime[i]] = cnt ;
            else mp[prime[i]] = cnt ;
        }

    }
    if(X != 1){
        if(ok) Xprime[X] = 1 ;
        else mp[X] = 1 ;
    }

}
void clr() {

  mp.clear() ;
  prefixSum.clear() ;
  Xprime.clear() ;

}
void solve()
{
  cin >> n >> x ;
  Xprime[1] = 1 ;
  primefactor(x , 1) ;
  for (auto &it : Xprime) prefixSum[it.F] = vector<int>(n + 1, 0);

  for(int i = 1 ; i <= n ; i++){
    cin >> a ;
    mp[1] = 1 ;
    primefactor(a , 0) ;
    for(auto it : Xprime) {
        prefixSum[it.F][i] = prefixSum[it.F][i - 1] + mp[it.F] ;
    }
    mp.clear() ;
  }
  cin >> q ;
  while(q--){
    cin >> l >> r ;
    int ok = 0 ;
    for(auto it : Xprime){
        int cur = prefixSum[it.F][r] - prefixSum[it.F][l - 1] ;
        if(cur >= it.S) ok++ ;
    }
    if(ok == Xprime.size()) cout << "Yes" << endl ;
    else cout << "No" << endl ;
  }
  clr() ;
}
int main()
{
     __Heart__
     seive() ;
     int t ; cin >> t ; while(t--) solve() ;
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-31 17:14:03
Judged At
2024-11-11 02:34:21
Judged By
Score
95
Total Time
≥1571ms
Peak Memory
≥4.961 MiB