/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 12ms 12.148 MiB
#2 Accepted 13ms 12.176 MiB
#3 Accepted 573ms 12.508 MiB
#4 Accepted 551ms 12.418 MiB
#5 Time Exceeded ≥1582ms ≥12.754 MiB
#6 Time Exceeded ≥1597ms ≥12.742 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define dbg(a,b,c,d) cerr<<a<<"  "<<b<<"  "<<c<<"  "<<d<<endl;
#define kill(a) {cout<<a<<endl;continue;}
#define KILL(a) {cout<<a<<endl;return 0;}
#define debug cerr<<"Error Found"<<endl;
#define mem(a,b) memset(a,b,sizeof(a))
#define lcm(a, b) (a/__gcd(a,b))*b
#define w(t) cin>>t;while(t--)
#define pi  2 * acos(0.0)
#define endl "\n"
int t, cs = 0;
const int mxn = 1e5 + 3, mod = 1e9 + 7;
vector<pair<int,int>>tre[mxn * 4], adj[mxn];



void build(int st, int ed, int node)
{
    //if(st == ed)return void(tre[node] = ar[st]);

    map<int,int>mp;
    for(int i = st; i <= ed; i++)
    {
        for(auto I:adj[i])mp[I.first] += I.second;
    }
    //dbg(st, ed, node, mp.size());
    for(auto i:mp)tre[node].push_back(make_pair(i.first, i.second));
    if(st == ed)return;
    int mid = st + ed >> 1;
    build(st, mid, node * 2);
    build(mid + 1, ed, node * 2 + 1);
    //tre[node] = tre[node * 2], tre[node * 2 + 1];
}
map<int, int>cur;

void query(int st, int ed, int node, int l, int r)
{
    if(st > r or ed < l)return;
    if(st >= l and ed <= r)
    {
       //cout << tre[node].size() << endl;
        for(auto i:tre[node])
        {
           // cout << i.first <<" "<<i.second << endl;
            cur[i.first] += i.second;
        }
        return;
    }
    int mid = st + ed >> 1;
    query(st, mid, node * 2, l, r), query(mid + 1, ed, node * 2 + 1, l, r);
}
bool vis[mxn];
int prime[mxn];
void sieve()
{
    vis[1] = true;
    for(int i = 2; i * i < mxn; i++)if(!vis[i])for(int j = i * i; j < mxn; j += i)vis[j] = true;
    for(int i = 2; i < mxn; i++)if(!vis[i])prime[cs++] = i;
}
void refresh(int n)
{
    for(int i = 1; i <= n * 4; i++)adj[i].clear(), tre[i].clear();
}
int32_t main()
{
    sieve();

    fast;
    w(t)
    {
        int n, k;
        cin >> n >> k;

        int ar[n + 1];
        refresh(n);
        map<int,int>need;

        for(int i = 0; i < cs and 1LL * prime[i] * prime[i] <= k; i++)
        {
            if(k % prime[i] == 0)
            {
                int cnt = 0;
                while(k % prime[i] == 0)k /= prime[i], cnt++;
                need[prime[i]] += cnt;
            }
        }

        if(k > 1)need[k]++;
        for(int j = 1; j <= n; j++)
        {
            cin >> ar[j];
            int a = ar[j];
            vector<pair<int,int>>vv;
            for(int i = 0; i < cs and 1LL * prime[i] * prime[i] <= a; i++)
            {
                if(a % prime[i] == 0)
                {
                    int cnt = 0;
                    while(a % prime[i] == 0)a /= prime[i], cnt++;
                    vv.push_back(make_pair(prime[i], cnt));
                }
            }
            if(a > 1)vv.push_back(make_pair(a, 1));

            for(auto I:vv)adj[j].push_back(make_pair(I.first, I.second));
        }
        build(1, n, 1);
        int q;
        cin >> q;
        while(q--)
        {
            int l, r;
            cin >> l >> r;
            cur.clear();
            bool f = true;
            query(1, n, 1, l, r);
            //for(auto i:cur)cout << i.first <<" "<<i.second << endl;
            for(auto i:need)if(cur[i.first] >= i.second);else{ f = false;break;}
            cout << (f ? "Yes" : "No") << endl;
        }
    }


}

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:26:20
Judged At
2024-11-11 02:27:21
Judged By
Score
7
Total Time
≥1597ms
Peak Memory
≥12.754 MiB