/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 2.32 MiB
#2 Accepted 4ms 2.32 MiB
#3 Accepted 185ms 2.848 MiB
#4 Accepted 184ms 2.844 MiB
#5 Accepted 207ms 916.0 KiB
#6 Accepted 210ms 888.0 KiB
#7 Accepted 249ms 2.922 MiB
#8 Accepted 242ms 2.918 MiB
#9 Accepted 245ms 2.91 MiB
#10 Accepted 287ms 5.43 MiB
#11 Accepted 284ms 5.633 MiB
#12 Accepted 286ms 4.07 MiB
#13 Accepted 251ms 2.926 MiB
#14 Accepted 238ms 2.879 MiB
#15 Accepted 185ms 2.832 MiB
#16 Accepted 185ms 2.816 MiB
#17 Accepted 188ms 2.891 MiB
#18 Accepted 189ms 2.809 MiB
#19 Accepted 211ms 2.852 MiB
#20 Accepted 244ms 2.918 MiB
#21 Accepted 278ms 5.34 MiB
#22 Accepted 284ms 3.871 MiB
#23 Accepted 279ms 5.617 MiB
#24 Accepted 290ms 5.684 MiB
#25 Accepted 304ms 5.672 MiB
#26 Accepted 213ms 2.832 MiB
#27 Accepted 602ms 6.078 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-11 02:30:46
Judged By
Score
100
Total Time
602ms
Peak Memory
6.078 MiB