/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 2ms 340.0 KiB
#3 Accepted 96ms 872.0 KiB
#4 Accepted 97ms 824.0 KiB
#5 Accepted 126ms 872.0 KiB
#6 Accepted 127ms 888.0 KiB
#7 Accepted 157ms 1.16 MiB
#8 Accepted 155ms 1.27 MiB
#9 Accepted 108ms 1.145 MiB
#10 Accepted 137ms 4.625 MiB
#11 Accepted 139ms 4.605 MiB
#12 Accepted 136ms 4.629 MiB
#13 Accepted 108ms 1.117 MiB
#14 Accepted 107ms 1.195 MiB
#15 Accepted 59ms 760.0 KiB
#16 Accepted 60ms 788.0 KiB
#17 Accepted 59ms 836.0 KiB
#18 Accepted 60ms 900.0 KiB
#19 Accepted 85ms 832.0 KiB
#20 Accepted 110ms 1.27 MiB
#21 Accepted 138ms 4.594 MiB
#22 Accepted 142ms 4.527 MiB
#23 Accepted 137ms 4.621 MiB
#24 Accepted 136ms 4.664 MiB
#25 Accepted 136ms 4.625 MiB
#26 Accepted 62ms 732.0 KiB
#27 Accepted 269ms 5.109 MiB

Code

#ifndef LOCAL
#include <bits/stdc++.h>
#define debug(...)
#endif

using namespace std;
#define int long long
#define cinv(v) for (auto &it:v) cin>>it;
#define coutv(v) for (auto &it:v) cout<< it<<' '; cout<<'\n';

int n, q, x;
vector<int> tree;

void update(int node, int start, int end, int idx, int val) {
    if (start > idx || end < idx) return;
    if (start == end) {
        tree[node] = val % x;
        return;
    }
    int mid = (start + end) / 2;
    update(node * 2, start, mid, idx, val);
    update(node * 2 + 1, mid + 1, end, idx, val);
    tree[node] = (tree[node * 2] * tree[node * 2 + 1]) % x;
}

int query(int node, int start, int end, int l, int r) {
    if (start > r || end < l) return 1;
    if (start >= l && end <= r) return tree[node];
    int mid = (start + end) / 2;
    int q1 = query(node * 2, start, mid, l, r);
    int q2 = query(node * 2 + 1, mid + 1, end, l, r);
    return (q1 * q2) % x;
}

void shelby() {
    cin >> n >> x;
    tree.assign(4 * n + 10, 1);
    vector<int> v(n + 1);
    for (int i = 1; i <= n; ++i) cin >> v[i], update(1, 1, n, i, v[i]);;
    debug(v);
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        debug(l, r);
        if (query(1, 1, n, l, r)) cout << "No\n";
        else cout << "Yes\n";
    }
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        // cout << "Case " << _ << ": ";
        shelby();
    }
}

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:43:36
Judged At
2024-11-05 15:43:36
Judged By
Score
100
Total Time
269ms
Peak Memory
5.109 MiB