/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 2ms 320.0 KiB
#3 Accepted 64ms 848.0 KiB
#4 Accepted 62ms 864.0 KiB
#5 Accepted 86ms 880.0 KiB
#6 Accepted 86ms 840.0 KiB
#7 Accepted 112ms 1.191 MiB
#8 Accepted 112ms 1.23 MiB
#9 Accepted 113ms 1.176 MiB
#10 Accepted 144ms 4.574 MiB
#11 Accepted 143ms 4.598 MiB
#12 Accepted 149ms 4.555 MiB
#13 Accepted 114ms 1.191 MiB
#14 Accepted 119ms 1.18 MiB
#15 Accepted 60ms 724.0 KiB
#16 Accepted 60ms 620.0 KiB
#17 Accepted 60ms 844.0 KiB
#18 Accepted 63ms 704.0 KiB
#19 Accepted 89ms 772.0 KiB
#20 Accepted 120ms 1.207 MiB
#21 Accepted 155ms 4.637 MiB
#22 Accepted 154ms 4.566 MiB
#23 Accepted 149ms 4.578 MiB
#24 Accepted 153ms 4.73 MiB
#25 Accepted 146ms 4.66 MiB
#26 Accepted 63ms 832.0 KiB
#27 Accepted 298ms 5.043 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-11 02:29:56
Judged By
Score
100
Total Time
298ms
Peak Memory
5.043 MiB