/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 2ms 324.0 KiB
#3 Accepted 71ms 864.0 KiB
#4 Accepted 71ms 856.0 KiB
#5 Accepted 98ms 816.0 KiB
#6 Accepted 99ms 904.0 KiB
#7 Accepted 132ms 1.223 MiB
#8 Accepted 133ms 1.285 MiB
#9 Accepted 135ms 1.215 MiB
#10 Accepted 171ms 5.34 MiB
#11 Accepted 171ms 5.488 MiB
#12 Accepted 169ms 5.379 MiB
#13 Accepted 134ms 1.262 MiB
#14 Accepted 134ms 1.254 MiB
#15 Accepted 71ms 820.0 KiB
#16 Accepted 71ms 808.0 KiB
#17 Accepted 72ms 724.0 KiB
#18 Accepted 73ms 844.0 KiB
#19 Accepted 101ms 896.0 KiB
#20 Accepted 133ms 1.277 MiB
#21 Accepted 171ms 5.504 MiB
#22 Accepted 176ms 5.336 MiB
#23 Accepted 170ms 5.445 MiB
#24 Accepted 169ms 5.523 MiB
#25 Accepted 166ms 5.512 MiB
#26 Accepted 72ms 680.0 KiB
#27 Accepted 331ms 5.879 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-11 02:29:27
Judged By
Score
100
Total Time
331ms
Peak Memory
5.879 MiB