/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 2ms 320.0 KiB
#3 Accepted 84ms 836.0 KiB
#4 Accepted 84ms 856.0 KiB
#5 Accepted 108ms 908.0 KiB
#6 Accepted 121ms 836.0 KiB
#7 Accepted 152ms 1.117 MiB
#8 Accepted 162ms 1.148 MiB
#9 Accepted 170ms 1.035 MiB
#10 Accepted 198ms 3.621 MiB
#11 Accepted 133ms 3.664 MiB
#12 Accepted 222ms 3.582 MiB
#13 Accepted 151ms 1.047 MiB
#14 Accepted 166ms 1.137 MiB
#15 Accepted 88ms 756.0 KiB
#16 Accepted 89ms 848.0 KiB
#17 Accepted 69ms 904.0 KiB
#18 Accepted 85ms 764.0 KiB
#19 Accepted 117ms 848.0 KiB
#20 Accepted 162ms 1.16 MiB
#21 Accepted 142ms 3.695 MiB
#22 Accepted 335ms 3.578 MiB
#23 Accepted 102ms 3.711 MiB
#24 Accepted 101ms 3.707 MiB
#25 Accepted 104ms 3.68 MiB
#26 Accepted 68ms 876.0 KiB
#27 Accepted 199ms 3.852 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-11 02:27:36
Judged By
Score
100
Total Time
335ms
Peak Memory
3.852 MiB