/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 580.0 KiB
#2 Accepted 2ms 580.0 KiB
#3 Accepted 145ms 776.0 KiB
#4 Accepted 140ms 928.0 KiB
#5 Accepted 233ms 1.137 MiB
#6 Accepted 220ms 1.172 MiB
#7 Accepted 296ms 3.934 MiB
#8 Accepted 473ms 4.211 MiB
#9 Accepted 306ms 3.691 MiB
#10 Accepted 532ms 28.676 MiB
#11 Accepted 348ms 25.945 MiB
#12 Accepted 354ms 25.898 MiB
#13 Accepted 288ms 4.207 MiB
#14 Accepted 366ms 3.84 MiB
#15 Accepted 152ms 872.0 KiB
#16 Accepted 152ms 916.0 KiB
#17 Accepted 116ms 836.0 KiB
#18 Accepted 146ms 904.0 KiB
#19 Accepted 221ms 1.129 MiB
#20 Accepted 367ms 3.906 MiB
#21 Accepted 1020ms 37.043 MiB
#22 Accepted 845ms 33.539 MiB
#23 Accepted 375ms 28.836 MiB
#24 Time Exceeded ≥1573ms ≥102.129 MiB
#25 Accepted 342ms 28.797 MiB
#26 Accepted 75ms 824.0 KiB
#27 Accepted 728ms 29.199 MiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define life_is_a_race ios::sync_with_stdio(false); cin.tie(nullptr);

bool notprime[32002];
vector<int>allprime;
void seive()
{
    for(int i=2;i<=1000;i++)
    {
        if(notprime[i]) continue;
        for(int j=i+i;j<=32000;j+=i) notprime[j]=true;
    }
    for(int i=2;i<=32000;i++) {if(!notprime[i]) allprime.push_back(i);}
}

int n,x;

void combine(map<int,int>&m, map<int,int>&m1,map<int,int>&m2)
{
    for(auto e:m1) m[e.first]+= e.second;
    for(auto e:m2) m[e.first]+= e.second;
}

void buildsg(int node,int start,int end,vector<int>&a,vector<map<int,int>>&sg,map<int,int>&mx)
{
    if(start == end)
    {
        for(auto e:mx)
        {
            while(a[start] % e.first == 0)
            {
                sg[node][e.first] ++;
                a[start] /= e.first;
            }
        }
        return;
    }
    int mid = (start+end)/2;
    buildsg(node*2,start,mid,a,sg,mx);
    buildsg(node*2+1,mid+1,end,a,sg,mx);
    combine(sg[node],sg[node*2],sg[node*2+1]);
}

map<int,int> query(int node,int start,int end,int l,int r,vector<map<int,int>>&sg)
{
    map<int,int> m;
    if(l>end || r<start) return m;
    if(l<=start && r>=end) return sg[node];
    int mid = (start+end)/2;
    map<int,int> m1 = query(node*2,start,mid,l,r,sg);
    map<int,int> m2 = query(node*2+1,mid+1,end,l,r,sg);
    combine(m,m1,m2);
    return m;
}

int main()
{
    life_is_a_race;
    seive();
    int t; cin>>t; while(t--)
    {
        //cout<<"Case "<<tc<<": ";
        cin >> n >> x;
        vector<int> a(n+1);
        for(int i=0;i<n;i++) cin>>a[i];
        
        map<int,int> mx;
        for(auto e:allprime)
        {
            if(e>x) break;
            while(x%e==0)
            {
                mx[e]++;
                x /= e;
            }
        }
        if(x > 1) mx[x]++;
            
        vector<map<int,int>> sg(4*n+5);
        buildsg(1,0,n-1,a,sg,mx);

        int q; cin>>q; while(q--)
        {
            int l,r; cin>>l>>r;
            map<int,int> m = query(1,0,n-1,l-1,r-1,sg);
            bool ok = true;
            
            for(auto e:mx)
            {
                if(m[e.first] < e.second) 
                {
                    ok = false;
                    break;
                }
            }
            if(ok) cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
    }
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-04 19:32:02
Judged At
2024-11-11 02:33:17
Judged By
Score
98
Total Time
≥1573ms
Peak Memory
≥102.129 MiB