/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 320.0 KiB
#2 Wrong Answer 1ms 532.0 KiB
#3 Wrong Answer 50ms 852.0 KiB

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];
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];
          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]);       // 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];
      }

     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));  // change this
    }
};



void solve(int cs){
    int n, x; 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 17:23:08
Judged At
2024-11-05 17:23:08
Judged By
Score
1
Total Time
50ms
Peak Memory
852.0 KiB