/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 51ms 836.0 KiB
#4 Accepted 48ms 860.0 KiB
#5 Accepted 66ms 788.0 KiB
#6 Accepted 63ms 788.0 KiB
#7 Accepted 81ms 1.012 MiB
#8 Accepted 106ms 1.02 MiB
#9 Accepted 79ms 1.008 MiB
#10 Accepted 120ms 2.52 MiB
#11 Accepted 98ms 2.723 MiB
#12 Accepted 123ms 2.668 MiB
#13 Accepted 85ms 1.02 MiB
#14 Accepted 104ms 1.004 MiB
#15 Accepted 48ms 796.0 KiB
#16 Accepted 49ms 788.0 KiB
#17 Accepted 47ms 788.0 KiB
#18 Accepted 48ms 860.0 KiB
#19 Accepted 72ms 836.0 KiB
#20 Accepted 81ms 1.012 MiB
#21 Accepted 100ms 2.77 MiB
#22 Accepted 107ms 2.566 MiB
#23 Accepted 97ms 2.816 MiB
#24 Accepted 98ms 2.836 MiB
#25 Accepted 98ms 2.77 MiB
#26 Accepted 48ms 788.0 KiB
#27 Accepted 202ms 3.141 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define dbg(a,b,c,d) cerr<<a<<"  "<<b<<"  "<<c<<"  "<<d<<endl;
#define kill(a) {cout<<a<<endl;continue;}
#define KILL(a) {cout<<a<<endl;return 0;}
#define debug cerr<<"Error Found"<<endl;
#define mem(a,b) memset(a,b,sizeof(a))
#define lcm(a, b) (a/__gcd(a,b))*b
#define w(t) cin>>t;while(t--)
#define pi  2 * acos(0.0)
#define endl "\n"
int t, cs = 0;
const int mxn = 1e5 + 3, mod = 1e9 + 7;
int tre[mxn * 4];
int ar[mxn], X;
void build(int st, int ed, int node)
{
    if(st == ed)return void(tre[node] = ar[st]);
    if(st == ed)return;
    int mid = st + ed >> 1;
    build(st, mid, node * 2);
    build(mid + 1, ed, node * 2 + 1);
    tre[node] = 1LL * tre[node * 2] * tre[node * 2 + 1] % X;
}

int query(int st, int ed, int node, int l, int r)
{
    if(st > r or ed < l)return 1;
    if(st >= l and ed <= r)return tre[node];
    int mid = st + ed >> 1;
    return 1LL * query(st, mid, node * 2, l, r) * query(mid + 1, ed, node * 2 + 1, l, r) % X;
}

void refresh(int n)
{
    for(int i = 1; i <= n * 4; i++)tre[i] = 0;
}
int32_t main()
{
    fast;
    w(t)
    {
        int n;
        cin >> n >> X;
        refresh(n);
        for(int j = 1; j <= n; j++)cin >> ar[j];
        build(1, n, 1);
        int q;
        cin >> q;
        while(q--)
        {
            int l, r;
            cin >> l >> r;

            bool f = (query(1, n, 1, l, r) % X == 0);
            cout << (f ? "Yes" : "No") << endl;
        }
    }


}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 17:39:57
Judged At
2024-11-05 17:39:57
Judged By
Score
100
Total Time
202ms
Peak Memory
3.141 MiB