/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 2ms 320.0 KiB
#3 Accepted 69ms 836.0 KiB
#4 Accepted 69ms 840.0 KiB
#5 Accepted 89ms 824.0 KiB
#6 Accepted 92ms 864.0 KiB
#7 Accepted 115ms 1.238 MiB
#8 Accepted 115ms 1.223 MiB
#9 Accepted 115ms 1.156 MiB
#10 Accepted 137ms 4.551 MiB
#11 Accepted 138ms 4.684 MiB
#12 Accepted 137ms 4.492 MiB
#13 Accepted 113ms 1.0 MiB
#14 Accepted 106ms 1.188 MiB
#15 Accepted 75ms 836.0 KiB
#16 Accepted 75ms 828.0 KiB
#17 Accepted 70ms 824.0 KiB
#18 Accepted 72ms 688.0 KiB
#19 Accepted 91ms 904.0 KiB
#20 Accepted 112ms 1.223 MiB
#21 Accepted 140ms 4.734 MiB
#22 Accepted 136ms 4.629 MiB
#23 Accepted 120ms 4.715 MiB
#24 Accepted 121ms 4.746 MiB
#25 Accepted 120ms 4.586 MiB
#26 Accepted 66ms 704.0 KiB
#27 Accepted 237ms 5.031 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-11 02:25:49
Judged By
Score
100
Total Time
237ms
Peak Memory
5.031 MiB