/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 328.0 KiB
#2 Accepted 2ms 540.0 KiB
#3 Accepted 67ms 824.0 KiB
#4 Accepted 65ms 872.0 KiB
#5 Accepted 92ms 1.074 MiB
#6 Accepted 92ms 868.0 KiB
#7 Accepted 120ms 1.238 MiB
#8 Accepted 120ms 1.148 MiB
#9 Accepted 129ms 1.199 MiB
#10 Accepted 151ms 5.414 MiB
#11 Accepted 149ms 5.488 MiB
#12 Accepted 154ms 5.324 MiB
#13 Accepted 126ms 1.246 MiB
#14 Accepted 120ms 1.266 MiB
#15 Accepted 65ms 836.0 KiB
#16 Accepted 65ms 832.0 KiB
#17 Accepted 66ms 844.0 KiB
#18 Accepted 67ms 836.0 KiB
#19 Accepted 92ms 904.0 KiB
#20 Accepted 122ms 1.062 MiB
#21 Accepted 151ms 5.738 MiB
#22 Accepted 152ms 5.512 MiB
#23 Accepted 150ms 5.352 MiB
#24 Accepted 150ms 5.371 MiB
#25 Accepted 149ms 5.465 MiB
#26 Accepted 67ms 844.0 KiB
#27 Accepted 301ms 5.812 MiB

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){
        return ((a%x)*(b%x))%x;
    }
    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 1;
        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);
        }
    }
};
int binpow(int a,int b,int MOD){
    a%=MOD;
    int res=1;
    while(b>0){
        if(b&1)res = res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
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);
        if(g==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:53:25
Judged At
2024-11-05 15:53:25
Judged By
Score
100
Total Time
301ms
Peak Memory
5.812 MiB