/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 556.0 KiB
#2 Accepted 2ms 596.0 KiB
#3 Accepted 59ms 800.0 KiB
#4 Accepted 59ms 872.0 KiB
#5 Accepted 106ms 1.059 MiB
#6 Accepted 67ms 1.02 MiB
#7 Accepted 102ms 2.656 MiB
#8 Accepted 79ms 2.84 MiB
#9 Accepted 79ms 2.812 MiB
#10 Accepted 137ms 20.523 MiB
#11 Accepted 134ms 20.812 MiB
#12 Accepted 148ms 20.699 MiB
#13 Accepted 79ms 2.867 MiB
#14 Accepted 79ms 2.781 MiB
#15 Accepted 70ms 872.0 KiB
#16 Accepted 59ms 1.066 MiB
#17 Accepted 59ms 1.02 MiB
#18 Accepted 61ms 788.0 KiB
#19 Accepted 71ms 1.023 MiB
#20 Accepted 81ms 2.77 MiB
#21 Accepted 142ms 20.793 MiB
#22 Accepted 138ms 20.648 MiB
#23 Accepted 145ms 20.785 MiB
#24 Accepted 142ms 20.559 MiB
#25 Accepted 137ms 20.871 MiB
#26 Accepted 61ms 864.0 KiB
#27 Accepted 249ms 21.219 MiB

Code

#include "bits/stdc++.h"
using namespace std;
using ll=long long;
void solve();
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cout << setprecision(8) << fixed;
    int t=1;
    cin>>t;
    for(int i=1;i<=t;i++){
        // cout<<"Test case# "<<i<<" ";
         solve();
    }
    return 0;
}
void solve(){
    ll n,x;cin>>n>>x;  
    vector<ll>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    ll K=25;
    ll st[K][n+1];
    std::copy(a.begin(), a.end(), st[0]);
    for (int i = 1; i <= K; i++)
        for (int j = 0; j + (1 << i) <= n; j++)
            st[i][j] = (st[i - 1][j]* st[i - 1][j + (1 << (i - 1))])%x;   
    
    ll q;cin>>q;  
    while(q--){
        ll l,r;cin>>l>>r;
        ll prod=1;
        l--,r--;
        for(int i=K;i>=0;i--){
            if((1<<i)<=(r-l+1)){
                prod=(prod%x*st[i][l]%x)%x;
                l+=(1<<i);
            }
        }
        // cout<<prod<<endl;
        if(prod%x==0){
            cout<<"Yes"<<'\n';
        }else{
            cout<<"No"<<'\n';
        }
    }
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-14 04:03:57
Judged At
2024-11-14 04:03:57
Judged By
Score
100
Total Time
249ms
Peak Memory
21.219 MiB