/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 2ms 324.0 KiB
#3 Accepted 47ms 668.0 KiB
#4 Accepted 48ms 640.0 KiB
#5 Accepted 63ms 920.0 KiB
#6 Accepted 63ms 856.0 KiB
#7 Accepted 82ms 1.188 MiB
#8 Accepted 84ms 1008.0 KiB
#9 Accepted 79ms 1.156 MiB
#10 Accepted 107ms 3.574 MiB
#11 Accepted 105ms 3.684 MiB
#12 Accepted 105ms 3.59 MiB
#13 Accepted 80ms 1.168 MiB
#14 Accepted 82ms 1.145 MiB
#15 Accepted 47ms 840.0 KiB
#16 Accepted 46ms 844.0 KiB
#17 Accepted 47ms 836.0 KiB
#18 Accepted 48ms 816.0 KiB
#19 Accepted 64ms 1020.0 KiB
#20 Accepted 82ms 1.117 MiB
#21 Accepted 107ms 3.633 MiB
#22 Accepted 102ms 3.59 MiB
#23 Accepted 103ms 3.676 MiB
#24 Accepted 107ms 3.711 MiB
#25 Accepted 105ms 3.691 MiB
#26 Accepted 47ms 764.0 KiB
#27 Accepted 212ms 3.949 MiB

Code

#include<bits/stdc++.h>
#define endl '\n'
using ll = long long;
using namespace std;

const int N = 3e5 + 9;
ll n, m;
struct Segment_Tree {
    ll t[4 * N];

    auto merge(auto &l, auto &r) { // <= Change this function
        return (l * r) % m;
    }
    void build(int node, int st, int en, vector<ll> &arr) { //=> O(N)
        if (st == en) {
            t[node] = arr[st];
            return;
        }
        int mid = (st + en) >> 1;
        build(node << 1, st, mid, arr); // divide left side
        build(node << 1 | 1, mid + 1, en, arr); // divide right side
        // Merging left and right portion
        auto &Cur = t[node];
        auto &Left = t[node << 1];
        auto &Right = t[node << 1 | 1];
        Cur = merge(Left, Right);
        return;
    }
    void update(int node, int st, int en, int idx, ll val) { //=> O(log n)
        if (st == en) {
            t[node] = val;
            return;
        }
        int mid = (st + en) >> 1;
        if (idx <= mid) update(node << 1, st, mid, idx, val);
        else update(node << 1 | 1, mid + 1, en, idx, val);
        // Merging left and right portion
        auto &Cur = t[node];
        auto &Left = t[node << 1];
        auto &Right = t[node << 1 | 1];
        Cur = merge(Left, Right);
        return;
    }
    ll query(int node, int st, int en, int l, int r) { //=> O(log n)
        if (st > r || en < l) { // No overlapping and out of range
            return 1; // <== careful 
        }
        if (l <= st && en <= r) { // Complete overlapped (l-r in range)
            return t[node];
        }
        // Partial overlapping
        int mid = (st + en) >> 1;
        auto Left = query(node << 1, st, mid, l, r);
        auto Right = query(node << 1 | 1, mid + 1, en, l, r);
        return merge(Left, Right);
    }
} st;

void solve() {
    cin >> n >> m;
    vector<ll> v(n + 1);
    for (int i = 1; i <= n; i++) {
        ll x; cin >> x;
        v[i] = x;
    }
    st.build(1, 1, n, v); // Creating Segment tree;
    int q;
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        ll val = st.query(1, 1, n, l, r);
        if(val == 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    return;
}

signed main() {
    ios::sync_with_stdio(false);cin.tie(0), cin.tie(0);
    int tc = 1;
    cin >> tc;
    for (int i = 1; i <= tc; ++i) {
        // cout << "Case " << i << ":\n";
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-07 15:39:13
Judged At
2024-11-11 02:23:11
Judged By
Score
100
Total Time
212ms
Peak Memory
3.949 MiB