/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 5ms 2.02 MiB
#2 Accepted 34ms 5.02 MiB
#3 Time Exceeded ≥1500ms ≥5.211 MiB
#4 Time Exceeded ≥1600ms ≥5.203 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:13:48
Judged At
2024-11-05 17:13:48
Judged By
Score
3
Total Time
≥1600ms
Peak Memory
≥5.211 MiB