/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 11ms 12.051 MiB
#2 Wrong Answer 12ms 11.941 MiB
#3 Wrong Answer 341ms 12.273 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];
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
void build(int st, int ed, int node)
{
    //if(st == ed)return void(tre[node] = ar[st]);

    gp_hash_table<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];
}
gp_hash_table<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);
        gp_hash_table<int,int>need;
        int a = k;
        for(int i = 0; i < cs and 1LL * prime[i] * prime[i] <= a; 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] <= ar[i]; 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:43:53
Judged At
2024-11-05 16:43:53
Judged By
Score
1
Total Time
341ms
Peak Memory
12.273 MiB