/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 560.0 KiB
#2 Accepted 2ms 540.0 KiB
#3 Accepted 141ms 2.914 MiB
#4 Accepted 125ms 2.809 MiB
#5 Accepted 138ms 2.871 MiB
#6 Accepted 143ms 2.641 MiB
#7 Accepted 161ms 2.93 MiB
#8 Accepted 162ms 2.816 MiB
#9 Accepted 159ms 2.875 MiB
#10 Accepted 191ms 3.859 MiB
#11 Accepted 183ms 5.262 MiB
#12 Accepted 189ms 5.523 MiB
#13 Accepted 162ms 3.062 MiB
#14 Accepted 206ms 2.91 MiB
#15 Accepted 161ms 2.832 MiB
#16 Accepted 126ms 2.723 MiB
#17 Accepted 121ms 1.02 MiB
#18 Accepted 123ms 836.0 KiB
#19 Accepted 142ms 2.766 MiB
#20 Accepted 159ms 2.875 MiB
#21 Accepted 194ms 5.461 MiB
#22 Accepted 182ms 5.715 MiB
#23 Accepted 189ms 5.66 MiB
#24 Accepted 183ms 3.895 MiB
#25 Accepted 189ms 4.023 MiB
#26 Accepted 124ms 2.785 MiB
#27 Accepted 365ms 4.438 MiB

Code

#include<bits/stdc++.h>
#define int long long
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define testing cout << "testing ";
#define mod 1000000007
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;


int tree[800004];
int arr[200001];
//give call init(1,1,n);
int x;
void init(int node,int b,int e){

    if(b==e){
        tree[node]=arr[b]%x;
        return;
    }
    int left=node*2;
    int right =node*2+1;
    int mid=(b+e)/2;

    init(left,b,mid);
    init(right,mid+1,e);
    tree[node]=(tree[left]*tree[right])%x;

}

int query(int node,int b,int e,int i, int j){

    if(i>e or j<b) return 1;
    if(b>=i and e<=j) return tree[node]%x;

    int left=node*2;
    int right =node*2+1;
    int mid=(b+e)/2;
    int p1=query(left,b,mid,i,j);
    int p2=query(right,mid+1,e,i,j);
    return (p1*p2)%x;
}

void update(int node,int b,int e,int i,int newvalue){
    if(i>e or i<b) return;
    if(b>=i and e<=i){
        tree[node]=newvalue;
        return;
    }
    int left=2*node;
    int right=node*2+1;
    int mid=(b+e)/2;
    update(left,b,mid,i,newvalue);
    update(right,mid+1,e,i,newvalue);
    tree[node]=tree[left]+tree[right];
}

////------lazy propagation-----
//
//struct info{
//    ll prop,sum;
//}tree[400001];
//
//int query(int node,int b, int e, int i, int j,int carry=0){
//    if(i>e or j<b) return 0;
//    if(b>=i and e<=j){
//        return tree[node].sum+carry*(e-b+1);
//    }
//
//    int left=node*2;
//    int right=node*2+1;
//    int mid=(b+e)/2;
//
//    int p1=query( left, b, mid, i, j,carry+tree[node].prop);
//    int p2=query( right, mid+1, e, i,j,carry+tree[node].prop);
//    return p1+p2;
//
//}
//
//void update(int node,int b,int e,int i,int j,ll x){
//    if(i>e or j<b) return;
//    if(b>=i and e<=j){
//
//        tree[node].sum+=((e-b+1)*x);
//        tree[node].prop+=x;
//        return;
//    }
//
//    int left=node*2;
//    int right =node*2+1;
//    int mid=(b+e)/2;
//    update(left,b,mid,i,j,x);
//    update(right,mid+1,e,i,j,x);
//    tree[node].sum=tree[left].sum+tree[right].sum+(e-b+1)*tree[node].prop;
//}



void do_the_honour(){

    int n; cin >> n >> x;

    for(int i=1;i<=n;i++) cin >> arr[i];

    init(1,1,n);

    int q;cin >> q;

    while(q--){
        int l,r; cin >> l >> r;


        if(query(1,1,n,l,r)==0) yes;
        else no;
    }

}

int32_t main(){
    optimize();
    int t=1;
    cin>>t;
    for(int z=1;z<=t;z++){


    do_the_honour();


}
    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:23:37
Judged At
2024-11-05 15:23:37
Judged By
Score
100
Total Time
365ms
Peak Memory
5.715 MiB