/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 38ms 632.0 KiB
#4 Accepted 38ms 788.0 KiB
#5 Accepted 48ms 788.0 KiB
#6 Accepted 49ms 780.0 KiB
#7 Accepted 60ms 1.211 MiB
#8 Accepted 61ms 1.152 MiB
#9 Accepted 60ms 1.004 MiB
#10 Accepted 75ms 4.652 MiB
#11 Accepted 78ms 4.652 MiB
#12 Accepted 77ms 4.562 MiB
#13 Accepted 60ms 1.215 MiB
#14 Accepted 60ms 1.156 MiB
#15 Accepted 39ms 652.0 KiB
#16 Accepted 39ms 788.0 KiB
#17 Accepted 37ms 788.0 KiB
#18 Accepted 42ms 788.0 KiB
#19 Accepted 52ms 788.0 KiB
#20 Accepted 63ms 1.008 MiB
#21 Accepted 77ms 4.52 MiB
#22 Accepted 73ms 4.52 MiB
#23 Accepted 73ms 4.52 MiB
#24 Accepted 80ms 4.566 MiB
#25 Accepted 73ms 4.57 MiB
#26 Accepted 61ms 788.0 KiB
#27 Accepted 142ms 4.941 MiB

Code

#include <bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
using ll = long long;

template<typename T, typename U = T>
struct SegmentTree {
  int n;
  vector<T> tree;
  ll MOD;

  // ----------

  template<typename VAL_T>
  T get_tree_val(VAL_T& val) {
    return (val % MOD);
  }

  T data_pull(T val_curr, U val_new) {
    return (val_new);
  }

  T merge(T a, T b) {
    return (a * b) % MOD;
  }

  // ----------

  SegmentTree(int n = 0) : n(n) {
    tree.resize(n<<2);
  }

  template<typename VAL_T>
  SegmentTree(vector<VAL_T>& data, ll x) : SegmentTree((int)data.size()) {
    MOD = x;
    __build(0, 0, n-1, data);
  }

  template<typename VAL_T>
  void __build(int ti, int left, int right, vector<VAL_T>& data) {
    if (left == right) {
      tree[ti] = get_tree_val(data[left]);
      return;
    }

    int tl, tr, tm;
    tl = (ti<<1)+1;
    tr = (ti<<1)+2;
    tm = (left+right)>>1;

    __build(tl, left, tm, data);
    __build(tr, tm+1, right, data);
    tree[ti] = merge(tree[tl], tree[tr]);
  }

  void __update(int ti, int left, int right, int ind, U val) {
    if (left == right) {
      tree[ti] = data_pull(tree[ti], val);
      return;
    }

    int tl, tr, tm;
    tl = (ti<<1)+1;
    tr = (ti<<1)+2;
    tm = (left+right)>>1;

    if (ind <= tm) __update(tl, left, tm, ind, val);
      else __update(tr, tm+1, right, ind, val);
    tree[ti] = merge(tree[tl], tree[tr]);
  }

  T __query(int ti, int left, int right, int l, int r) {
    if ((l <= left) && (right <= r)) return tree[ti];

    int tl, tr, tm;
    tl = (ti<<1)+1;
    tr = (ti<<1)+2;
    tm = (left+right)>>1;

    if (l > tm) return __query(tr, tm+1, right, l, r);
    if (r <= tm) return __query(tl, left, tm, l, r);
    return merge(
      __query(tl, left, tm, l, r),
      __query(tr, tm+1, right, l, r)
    );
  }

  void update(int i, U val) { __update(0, 0, n-1, i, val); }
  T query(int l, int r) { return __query(0, 0, n-1, l, r); }
};

int main() {
  FAST;
  
  int tc = 1, ti;
  cin >> tc;

  for (ti = 1; ti <= tc; ++ti) {
    ll n, q, i, l, r, x;
    cin >> n >> x;
    
    vector<ll> a(n);
    for (i = 0; i < n; ++i) cin >> a[i];

    SegmentTree<ll> seg(a, x);

    cin >> q; while (q--) {
      cin >> l >> r;
      --l; --r;
      x = seg.query(l, r);
      if (x == 0) cout << "Yes" << "\n";
        else cout << "No" << "\n";
    }
  }

  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 15:01:30
Judged At
2024-11-05 15:01:30
Judged By
Score
100
Total Time
142ms
Peak Memory
4.941 MiB