/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 364.0 KiB
#3 Accepted 100ms 868.0 KiB
#4 Accepted 79ms 868.0 KiB
#5 Accepted 123ms 788.0 KiB
#6 Accepted 110ms 788.0 KiB
#7 Accepted 138ms 1.168 MiB
#8 Accepted 146ms 1.02 MiB
#9 Accepted 177ms 1.309 MiB
#10 Accepted 169ms 3.566 MiB
#11 Accepted 144ms 3.52 MiB
#12 Accepted 196ms 3.582 MiB
#13 Accepted 140ms 1.172 MiB
#14 Accepted 167ms 1.148 MiB
#15 Accepted 83ms 844.0 KiB
#16 Accepted 83ms 788.0 KiB
#17 Accepted 65ms 832.0 KiB
#18 Accepted 97ms 792.0 KiB
#19 Accepted 112ms 788.0 KiB
#20 Accepted 150ms 1.02 MiB
#21 Accepted 153ms 3.562 MiB
#22 Accepted 299ms 3.562 MiB
#23 Accepted 114ms 3.484 MiB
#24 Accepted 86ms 3.566 MiB
#25 Accepted 87ms 3.516 MiB
#26 Accepted 84ms 828.0 KiB
#27 Accepted 193ms 3.891 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;

const int N = 1e5 + 9;

ll n, x, q;

struct Segment_Tree {
    ll t[4 * N];

    auto merge(ll l, ll r) { // <== Change this function
        return __gcd(l * r, x);
    }
    void build(int node, int st, int en, vector<ll> &arr) { //=> O(N)
        if (st == en) {
            t[node] = arr[st];
            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 = merge(Left, Right);
        return;
    }
    ll query(int node, int st, int en, int l, int r) { //=> O(log n)
        if (st > r || en < l) { // No overlapping and out of range
            return 1; // <== careful 
        }
        if (l <= st && en <= r) { // Complete overlapped (l-r in range)
            return t[node];
        }
        // Partial overlapping
        int mid = (st + en) >> 1;
        auto Left = query(node << 1, st, mid, l, r);
        auto Right = query(node << 1 | 1, mid + 1, en, l, r);
        return merge(Left, Right);
    }
} st1;

void solve() {
    cin >> n >> x;

    vector<ll> 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;
        // cout << st1.query(1, 0, n - 1, l, r) << endl;
        if(st1.query(1, 0, n - 1, l, r) % x == 0) 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
Contest
Brain Booster #7
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 16:20:40
Judged At
2024-11-05 16:20:40
Judged By
Score
100
Total Time
299ms
Peak Memory
3.891 MiB