/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 692.0 KiB
#2 Accepted 3ms 760.0 KiB
#3 Accepted 263ms 980.0 KiB
#4 Accepted 268ms 924.0 KiB
#5 Accepted 262ms 924.0 KiB
#6 Accepted 277ms 1.016 MiB
#7 Accepted 273ms 1.148 MiB
#8 Accepted 291ms 1.238 MiB
#9 Accepted 288ms 1.023 MiB
#10 Accepted 295ms 2.41 MiB
#11 Accepted 270ms 1.77 MiB
#12 Accepted 286ms 2.117 MiB
#13 Accepted 294ms 1.109 MiB
#14 Accepted 273ms 1.129 MiB
#15 Accepted 290ms 876.0 KiB
#16 Accepted 297ms 1.016 MiB
#17 Accepted 262ms 1.0 MiB
#18 Accepted 616ms 860.0 KiB
#19 Accepted 613ms 1.133 MiB
#20 Accepted 608ms 1.168 MiB
#21 Accepted 650ms 3.293 MiB
#22 Accepted 663ms 3.293 MiB
#23 Accepted 267ms 1.82 MiB
#24 Accepted 373ms 4.957 MiB
#25 Time Exceeded ≥1563ms ≥1.27 MiB
#26 Accepted 628ms 1.043 MiB
#27 Time Exceeded ≥1588ms ≥1.309 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;
unordered_map<int, vector<int>> prefixSum;
unordered_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-11-01 02:15:25
Judged At
2024-11-11 02:34:17
Judged By
Score
95
Total Time
≥1588ms
Peak Memory
≥4.957 MiB