/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Wrong Answer 2ms 540.0 KiB
#3 Wrong Answer 52ms 712.0 KiB

Code

#include<bits/stdc++.h>
#define endl        '\n'
#define F           first
#define S           second
#define pb          push_back
#define yes         cout<<"Yes\n"
#define no          cout<<"No\n"
#define all(x)      x.begin(),x.end()
#define allr(x)     x.rbegin(),x.rend()
#define error1(x)   cerr<<#x<<" = "<<(x)<<endl
#define error2(a,b) cerr<<"("<<#a<<", "<<#b<<") = ("<<(a)<<", "<<(b)<<")\n";
#define coutall(v)  for(auto &it: v) cout << it << " "; cout << endl;
using namespace std;
using ll = long long;
using ld = long double;

// 0-based indexing, query finds in range [first, last]
#define lg(x) (31 - __builtin_clz(x))
const int N = 3e5 + 7;
const int K = lg(N);

struct sparse_table {
    ll tr[N][K + 1];

    ll f(ll p1, ll p2) { // Change this function according to the problem.
        return p1 + p2; // <===
    }

    void build(int n, const vector<ll> &a) { // O(N * logN)
        for (int i = 0; i < n; i++) {
            tr[i][0] = a[i];
        }
        for (int j = 1; j <= K; j++) {
            for (int i = 0; i + (1 << j) <= n; i++) {
                tr[i][j] = f(tr[i][j - 1], tr[i + (1 << (j - 1))][j - 1]);
            }
        }
    }

    ll query1(int l, int r) { // find Sum, LCM => O(LogN)
        ll val = 0; // for sum => val = 0 and lcm => val = 1
        for (int j = K; j >= 0; j--) {
            if ((1 << j) <= r - l + 1) {
                val = f(val, tr[l][j]);
                l += 1 << j;
            }
        }
        return val;
    }

    ll query2(int l, int r) { // find Min, Max, GCD, AND, OR, XOR => O(1)
        int d = lg(r - l + 1);
        return f(tr[l][d], tr[r - (1 << d) + 1][d]);
    }
} spt;

void prime_factors(int n, vector<int> &pf) { // O(sqrt(n))
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            pf.push_back(i);
            n /= i;
        }
    }
    if (n > 1) pf.push_back(n);
    return;
}

void solve() {
    ll n, x, q;
    cin >> n >> x;
    vector<int> pf; 
    prime_factors(x, pf);

    vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        v[i] = __gcd(x, v[i]);
    }
    spt.build(n, v);

    cin >> q;
    int l, r;
    while(q--) {
        cin >> l >> r; --l, --r;
        if(spt.query2(l, r) % x == 0) yes;
        else no;
    }
    return;
}

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

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 16:08:17
Judged At
2024-11-11 02:28:20
Judged By
Score
1
Total Time
52ms
Peak Memory
712.0 KiB