結果

問題 No.854 公平なりんご分配
ユーザー MayimgMayimg
提出日時 2019-07-27 01:20:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,930 bytes
コンパイル時間 2,601 ms
コンパイル使用メモリ 215,508 KB
実行使用メモリ 18,276 KB
最終ジャッジ日時 2023-09-15 05:26:04
合計ジャッジ時間 18,337 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 RE -
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 RE -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,380 KB
testcase_21 WA -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 WA -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 WA -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
testcase_74 RE -
testcase_75 RE -
testcase_76 RE -
testcase_77 RE -
testcase_78 RE -
testcase_79 RE -
testcase_80 RE -
testcase_81 RE -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 AC 55 ms
17,848 KB
testcase_86 AC 48 ms
17,892 KB
testcase_87 RE -
testcase_88 RE -
testcase_89 RE -
testcase_90 RE -
testcase_91 RE -
testcase_92 RE -
testcase_93 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
template<typename T> class SparseTable {
private:
  vector<vector<T>> table;
  vector<int> height;
  using Func = function<T(T, T)>;
  Func f;
public:
  constexpr SparseTable() {}
  constexpr SparseTable(const Func& f_) : f(f_) {}
  constexpr SparseTable(const vector<T>& v, const Func& f_) : f(f_) { initialize(v); }
  constexpr void initialize(const vector<T>& v, const Func& f_) {
    f = f_;
    int n = (int) v.size(), h = 1;
    while ((1 << h) <= n) ++h;
    table.assign(h, vector<T>(n));
    height.assign((1 << h), 0);
    for (int i = 2; i < (1 << h); ++i) height[i] = height[i >> 1] + 1;
    for (int i = 0; i < n; ++i) table[0][i] = v[i];
    for (int i = 1; i < h; ++i) {
      int s = (1 << i);
      for (int j = 0; j < n; j += (s << 1)) {
        int t = min(j + s, n);
        table[i][t - 1] = v[t - 1];
        for (int k = t - 2; k >= j; --k) table[i][k] = f(v[k], table[i][k + 1]);
        if (n <= t) break;
        table[i][t] = v[t];
        for (int k = t + 1; k < min(t + s, n); ++k) table[i][k] = f(table[i][k - 1], v[k]);
      }
    }
  }
  constexpr void initialize(const vector<T>& v) {
    int n = (int) v.size(), h = 1;
    while ((1 << h) <= n) h++;
    table.assign(h, vector<T>(n));
    height.assign((1 << h), 0);
    for (int i = 2; i < (1 << h); ++i) height[i] = height[i << 1] + 1;
    for (int i = 0; i < n; ++i) table[0][i] = v[i];
    for (int i = 1; i < h; ++i) {
      int s = (1 << i);
      for (int j = 0; j < n; j += (s << 1)) {
        int t = min(j + s, n);
        table[i][t - 1] = v[t - 1];
        for (int k = t - 2; k >= j; --k) table[i][k] = f(v[k], table[i][k + 1]);
        if (n <= t) break;
        table[i][t] = v[t];
        for (int k = t + 1; k < min(t + s, n); ++k) table[i][k] = f(table[i][k - 1], v[k]);
      }
    }
  }
  constexpr T get(int l, int r) {
    if (l >= --r) return table[0][l];
    return f(table[height[l ^ r]][l], table[height[l ^ r]][r]);
  }
};
function<int(int, int)> MIN = [] (int a, int b) { return min(a, b);};
function<long long(long long, long long)> LLMIN = [] (long long a, long long b) { return min(a, b);};
function<int(int, int)> MAX = [] (int a, int b) { return max(a, b);};
function<long long(long long, long long)> LLMAX = [] (long long a, long long b) { return max(a, b);};
function<long long(long long, long long)> SUM = [] (long long a, long long b) { return a + b;};
function<long long(long long, long long)> PROD = [] (long long a, long long b) { return a * b;};

signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a.push_back(1);
  SparseTable sp(a, PROD);
  int q;
  cin >> q;
  while (q--) {
    int p, l, r;
    cin >> p >> l >> r;
    //6 4 6
    l--;
    cout << (sp.get(l, r) % p == 0 ? "Yes\n" : "NO\n");
  }  
  return 0;
}
0