/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 588.0 KiB
#2 Wrong Answer 4ms 584.0 KiB
#3 Wrong Answer 193ms 1.031 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 >  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, int pos , 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 ;
        }
        if(!ok && Xprime.find(prime[i]) != Xprime.end()) {
            prefixSum[prime[i]][pos] = cnt ;
            if(pos > 1)prefixSum[prime[i]][pos] += prefixSum[prime[i]][pos - 1] ;
        }

    }
    if(X != 1){
        if(ok) Xprime[X] = 1 ;
        else if(!ok && Xprime.find(X) != Xprime.end()){
            prefixSum[X][pos] = 1 ;
            if(pos > 1) prefixSum[X][pos] += prefixSum[X][pos - 1] ;
        }
    }

}
void clr() {

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

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

  cin >> q ;
  while(q--){
    cin >> l >> r ;
    bool ok = 1 ;
    for(auto it : Xprime){
        int cur = prefixSum[it.F][r] - prefixSum[it.F][l - 1] ;
        if(cur < it.S) {
            ok = 0 ;
            break ;
        }
    }
    if(ok) 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:10:23
Judged At
2024-11-11 02:34:17
Judged By
Score
1
Total Time
193ms
Peak Memory
1.031 MiB