/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 22ms 21.77 MiB
#2 Accepted 22ms 21.969 MiB
#3 Accepted 98ms 22.152 MiB
#4 Accepted 83ms 22.27 MiB
#5 Accepted 97ms 22.559 MiB
#6 Accepted 95ms 22.566 MiB
#7 Accepted 106ms 25.02 MiB
#8 Accepted 126ms 25.27 MiB
#9 Accepted 116ms 24.77 MiB
#10 Accepted 213ms 44.488 MiB
#11 Accepted 192ms 41.492 MiB
#12 Accepted 194ms 41.312 MiB
#13 Accepted 110ms 25.328 MiB
#14 Accepted 114ms 24.77 MiB
#15 Accepted 85ms 22.168 MiB
#16 Accepted 86ms 22.27 MiB
#17 Accepted 86ms 22.32 MiB
#18 Accepted 96ms 22.234 MiB
#19 Accepted 118ms 22.52 MiB
#20 Accepted 120ms 25.188 MiB
#21 Accepted 271ms 52.77 MiB
#22 Accepted 229ms 49.27 MiB
#23 Accepted 221ms 50.176 MiB
#24 Accepted 429ms 99.047 MiB
#25 Time Exceeded ≥1600ms ≥26.617 MiB
#26 Accepted 106ms 22.023 MiB
#27 Time Exceeded ≥1601ms ≥26.715 MiB

Code

#include<bits/stdc++.h>
#define endl        '\n'
#define F           first
#define S           second
#define pb          push_back
#define yes         cout<<"Yes\n"
#define no          cout<<"No\n"
#define all(x)      x.begin(),x.end()
#define allr(x)     x.rbegin(),x.rend()
#define error1(x)   cerr<<#x<<" = "<<(x)<<endl
#define error2(a,b) cerr<<"("<<#a<<", "<<#b<<") = ("<<(a)<<", "<<(b)<<")\n";
#define coutall(v)  for(auto &it: v) cout << it << " "; cout << endl;
using namespace std;
using ll = long long;
using ld = long double;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

// for gp_hash_table and unordered_map
struct custom_hash { 
    static uint64_t splitmix64(uint64_t x) {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x += FIXED_RANDOM;
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const { // x key
        return splitmix64(x);
    }
    size_t operator()(pair<uint64_t, uint64_t> x) const { // For, key = pair
        return splitmix64(x.first) ^ splitmix64(x.second);
    }
};

const int N = 1e5 + 3;

void add_prime_factors(int n, unordered_map<int, int, custom_hash> &mp) { // O(sqrt(n))
    int c;
    for (int i = 2; i * i <= n; i++) {
        c = 0;
        while (n % i == 0) {
            ++c;
            n /= i;
        }
        if(c) mp[i] += c;
    }
    if (n > 1) mp[n] += 1;
    return;
}

struct Merge_Sort_Tree {
    vector<unordered_map<int, int, custom_hash>> t;

    Merge_Sort_Tree() {
        t.resize(4 * N, {});
    }

    void build(int node, int st, int en, vector<int> &arr) { //=> O(N log N)
        t[node].clear();
        if (st == en) {
            // t[node] = {arr[st]};
            add_prime_factors(arr[st], t[node]);
            return;
        }
        int mid = (st + en) >> 1;
        build(node << 1, st, mid, arr); // divide left side
        build(node << 1 | 1, mid + 1, en, arr); // divide right side

        // Merging left and right portion
        auto &Cur = t[node];
        auto &Left = t[node << 1];
        auto &Right = t[node << 1 | 1];
        
        Cur = Left;
        // for(auto &[i, j]: Left) Cur[i] = j;
        for(auto &[i, j]: Right) Cur[i] += j;
    }
    
    void query(int node, int st, int en, int l, int r, int &x) { //=> O(log N * log N)
        // assert(l <= r); // <==
        if (st > r || en < l) { // No overlapping and out of range
            return; // <== careful 
        }
        if (l <= st && en <= r) { // Complete overlapped (l-r in range)
            int c;
            for(auto &[i, j]: t[node]) {
                c = j;
                while(x % i == 0 && c-- > 0) x /= i;
            }
            return;
        }
        // Partial overlapping
        int mid = (st + en) >> 1;
        query(node << 1, st, mid, l, r, x);
        query(node << 1 | 1, mid + 1, en, l, r, x);
        return;
    }
} st1;

void solve() {
    int n, x, q;
    cin >> n >> x;

    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        v[i] = __gcd(x, v[i]);
    }
    st1.build(1, 0, n - 1, v);

    cin >> q;
    int l, r;
    while(q--) {
        cin >> l >> r; --l, --r;
        int xx = x;
        st1.query(1, 0, n - 1, l, r, xx);
        if(xx == 1) yes;
        else no;
    }
    return;
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-06 18:43:16
Judged At
2024-11-06 18:43:16
Judged By
Score
95
Total Time
≥1601ms
Peak Memory
≥99.047 MiB