/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 1.074 MiB
#2 Accepted 3ms 1.004 MiB
#3 Accepted 186ms 1.242 MiB
#4 Accepted 183ms 1.355 MiB
#5 Accepted 206ms 1.824 MiB
#6 Accepted 231ms 1.484 MiB
#7 Accepted 285ms 5.926 MiB
#8 Accepted 328ms 6.469 MiB
#9 Accepted 380ms 6.43 MiB
#10 Accepted 439ms 45.531 MiB
#11 Accepted 298ms 35.117 MiB
#12 Accepted 381ms 41.125 MiB
#13 Accepted 304ms 7.098 MiB
#14 Accepted 280ms 6.359 MiB
#15 Accepted 224ms 1.176 MiB
#16 Accepted 227ms 1.199 MiB
#17 Accepted 153ms 1.27 MiB
#18 Accepted 466ms 1.02 MiB
#19 Accepted 486ms 1.723 MiB
#20 Accepted 604ms 7.352 MiB
#21 Accepted 822ms 58.637 MiB
#22 Accepted 859ms 60.633 MiB
#23 Accepted 175ms 7.656 MiB
#24 Accepted 1104ms 56.594 MiB
#25 Accepted 1428ms 7.633 MiB
#26 Accepted 426ms 1.445 MiB
#27 Time Exceeded ≥1597ms ≥7.535 MiB

Code

#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define endl '\n'
#define Endl '\n'

using namespace std;

const int N = 2e5 + 5;
int tc, n, x, a[N];
bool isPrime[N];
vector<int> primes;
map<int, int> xFact;
map<pair<int, int>, int> adj;

void sieve() {
    memset(isPrime, 1, sizeof isPrime);
    isPrime[0] = isPrime[1] = 0;
    for (int i = 2; i * i < N; i++) {
        if (isPrime[i]) {
            for (int j = i * i; j < N; j += i) {
                isPrime[j] = 0;
            }
        }
    }
    for (int i = 2; i < N; i++) {
        if (isPrime[i]) {
            primes.push_back(i);
        }
    }
}

map<int, int> factorize(int x) {
    map<int, int> fact;
    for (int i = 0; i < primes.size() && primes[i] * primes[i] <= x; i++) {
        while (x % primes[i] == 0) {
            fact[primes[i]]++;
            x /= primes[i];
        }
    }
    if (x > 1) {
        fact[x]++;
    }
    return fact;
}

void buildAdjascentList() {
    map<int, int> fact;
    set<int> st, seen;
    for (int i = 0; i < n; i++) {
        fact.clear();
        seen.clear();
        fact = factorize(a[i]);
        for (auto p : fact) {
            int previousVal = 0;
            if (i) {
                previousVal = adj[{i - 1, p.first}];
            }
            adj[{i, p.first}] = previousVal + p.second;
            seen.insert(p.first);
        }
        // fill the gaps
        for (auto p : xFact) {
            if (!seen.count(p.first)) {
                adj[{i, p.first}] = (i ? adj[{i - 1, p.first}] : 0);
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); // cout.tie(0);
    sieve();
    cin >> tc;
    while (tc--) {
        cin >> n >> x;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        xFact.clear();
        adj.clear();
        xFact = factorize(x);
        buildAdjascentList();

        int q;
        cin >> q;
        while (q--) {
            int l, r;
            cin >> l >> r;
            l--, r--;
            bool ok = 1;
            for (auto p : xFact) {
                int cnt = adj[{r, p.first}];
                if (l) {
                    cnt -= adj[{l - 1, p.first}];
                }
                if (cnt < p.second) {
                    ok = 0;
                    break;
                }
            }
            cout << (ok ? "Yes" : "No") << endl;
        }
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Contest
Lockout contest round-1 ( Mazharul Islam vs Thakur Emon)
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-04 17:33:18
Judged At
2024-11-04 17:33:18
Judged By
Score
97
Total Time
≥1597ms
Peak Memory
≥60.633 MiB