/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 69ms 732.0 KiB
#4 Accepted 64ms 788.0 KiB
#5 Accepted 86ms 788.0 KiB
#6 Accepted 85ms 1.082 MiB
#7 Accepted 107ms 1.141 MiB
#8 Accepted 103ms 1.254 MiB
#9 Accepted 107ms 1.211 MiB
#10 Accepted 128ms 4.504 MiB
#11 Accepted 125ms 4.52 MiB
#12 Accepted 128ms 4.52 MiB
#13 Accepted 107ms 1.145 MiB
#14 Accepted 106ms 1.203 MiB
#15 Accepted 73ms 836.0 KiB
#16 Accepted 68ms 788.0 KiB
#17 Accepted 66ms 788.0 KiB
#18 Accepted 70ms 788.0 KiB
#19 Accepted 85ms 788.0 KiB
#20 Accepted 107ms 1.121 MiB
#21 Accepted 153ms 4.52 MiB
#22 Accepted 126ms 4.422 MiB
#23 Accepted 110ms 4.551 MiB
#24 Accepted 106ms 4.52 MiB
#25 Accepted 109ms 4.52 MiB
#26 Accepted 64ms 788.0 KiB
#27 Accepted 215ms 4.961 MiB

Code

#include <bits/stdc++.h>
using namespace std;


#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define int long long
const int mod = 1e9 + 7, INF = 5e9, N = 1e5 + 2;

int a[N];
int n, x;
struct segTree{
    vector<int> tree;
 
    segTree(int n){
        tree.resize(4*(n+5));
        build(1, 1, n);
    }
 
    void build(int node, int b, int e){
       if(b==e){
          tree[node] = a[b]%x;
          return;
        }
    int l = 2*node, r = 2*node +1;
    int mid = (b+e)/2;

    build(l, b, mid);
    build(r, mid+1, e);
    tree[node] = (tree[l] * tree[r]) % x;       // change this
    return;
    }

 
    void upd(int node, int b, int e, int i, int x){
       if(e < i or i < b) return;
       if(b==e && b==i){
       tree[node] = x;            // update
       return;
     }

      int l = node*2, r = node*2 + 1;
      int mid = (b+e)/2;
      upd(l, b, mid, i, x);
      upd(r, mid+1, e, i, x);
      tree[node] = min(tree[l], tree [r]);
      return;         // change this
    }

 
    int query(int node, int b, int e, int i, int j){
       if(b > j or e < i) return 1;       // return appropriate value
       if(b >= i && e<= j){
        return tree[node] % x;
      }

     int l= 2*node, r = 2*node + 1;
     int mid = (e+b)/2;
     return ((query(l, b, mid, i, j) * query(r, mid + 1, e, i, j))%x);  // change this
    }
};



void solve(int cs){
    cin >> n >> x;
    for(int i = 1 ; i <= n ; i++){
        cin >> a[i];
        a[i] = __gcd(x, a[i]);
    }
    segTree st(n);
    st.build(1, 1, n);
    int q; cin >> q;
    while(q--){
        int l, r; cin >> l >> r;
        int val = st.query(1, 1, n, l, r);
        if(val%x == 0){
            cout<<"Yes\n";
        }
        else cout<<"No\n";
    }

}

//It's now, or never.
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int TEST = 1;
    cin >> TEST;

    for (int i = 1; i <= TEST; i++) {
      //  cout << "Case " << i << ":"<<'\n';
        solve(i);
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 18:25:59
Judged At
2024-11-05 18:25:59
Judged By
Score
100
Total Time
215ms
Peak Memory
4.961 MiB