/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 2ms 568.0 KiB
#3 Wrong Answer 86ms 716.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define f(i,x,y) for(int i=x;i<y;i++)
#define f2(i,x,y) for(int i=x;i>=y;i--)
#define pii pair<int,int>
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int MOD =1000000007;
const int INF = 1e18;
const int N = 2e5;
class SegmentTree
{
public:
    int n,x;
    vector<int>tree,arr;
    SegmentTree(vector<int>&v, int xx){
        x=xx;
        n = v.size();
        arr = v;
        tree.assign(4*n,0);
        build(1,0,n-1);
    }
    int query(int l,int r){return query(1,0,n-1,l,r);}
private:
    int merge(int a,int b){
        int g = __gcd(a,b);
        g = __gcd(g,x);
        return g;
    }
    void build(int node,int start,int end){
        if(start==end)tree[node] = arr[start];
        else {
            int mid = (start+end)/2;
            build(2*node,start,mid);
            build(2*node+1,mid+1,end);
            tree[node] = merge(tree[2*node],tree[2*node+1]);
        }
    }
    int query(int node,int start,int end,int l,int r){
        if(end<l or start>r)return 0;
        if(start==end)return tree[node];
        else if(l<=start and end<=r)return tree[node];
        else{
            int mid = (start+end)/2;
            int left = query(2*node,start,mid,l,r);
            int right = query(2*node+1,mid+1,end,l,r);
            return merge(left,right);
        }
    }
};
void solve(int tc){
    int n,x;
    cin >> n >> x;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin >> v[i];
    int q; cin >> q;
    SegmentTree sT(v,x);
    while(q--){
        int l , r; cin >> l >> r;
        l--,r--;
        int g = sT.query(l,r);
        int mod = (g%x * (r-l+1)%x)%x;
        if(mod==0)cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}
int32_t main(){

    Fast

    int t=1;

    cin >> t;

    for(int tc=1;tc<=t;tc++){

        solve(tc);
    }
    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 15:42:10
Judged At
2024-11-05 15:42:10
Judged By
Score
1
Total Time
86ms
Peak Memory
716.0 KiB