/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 3ms 4.574 MiB
#3 Accepted 66ms 4.844 MiB
#4 Accepted 66ms 4.824 MiB
#5 Accepted 77ms 6.918 MiB
#6 Accepted 77ms 6.863 MiB
#7 Accepted 93ms 12.949 MiB
#8 Accepted 88ms 12.801 MiB
#9 Accepted 90ms 12.715 MiB
#10 Accepted 126ms 17.57 MiB
#11 Accepted 124ms 14.699 MiB
#12 Accepted 123ms 17.637 MiB
#13 Accepted 89ms 12.934 MiB
#14 Accepted 87ms 11.148 MiB
#15 Accepted 71ms 4.953 MiB
#16 Accepted 63ms 4.867 MiB
#17 Accepted 60ms 4.867 MiB
#18 Accepted 69ms 8.797 MiB
#19 Accepted 80ms 6.719 MiB
#20 Accepted 97ms 10.957 MiB
#21 Accepted 127ms 15.461 MiB
#22 Accepted 141ms 15.598 MiB
#23 Accepted 136ms 17.699 MiB
#24 Accepted 133ms 15.453 MiB
#25 Accepted 130ms 15.621 MiB
#26 Accepted 68ms 4.805 MiB
#27 Accepted 242ms 14.809 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';

const int N = 1e5 + 5, K = 20;
int n, q, x, arr[N], st[K + 1][N];

void build() {
    copy(arr, arr + n + 1, st[0]);
    int k = __lg(n);
    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;
}

int query(int L, int R) {
    int ret = 1;
    for (int i = K; i >= 0; --i) {
        if ((1 << i) <= R - L + 1) {
            ret = (ret * st[i][L]) % x;
            L += 1 << i;
        }
    }
    return ret;
}

void shelby() {
    cin >> n >> x;
    for (int i = 1; i <= n; ++i) cin >> arr[i];
    build();
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        debug(l, r);
        if (query(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
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 17:14:29
Judged At
2024-11-11 02:26:11
Judged By
Score
100
Total Time
242ms
Peak Memory
17.699 MiB