結果

問題 No.854 公平なりんご分配
ユーザー kk
提出日時 2021-03-20 19:13:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,562 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 210,480 KB
実行使用メモリ 155,068 KB
最終ジャッジ日時 2023-08-13 13:05:22
合計ジャッジ時間 22,357 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

class factor {
  vector<int> p;
public:
  factor() : p(vector<int>(303)) {}
  factor(vector<int> p): p(p) {}
  int get(int i) const { return p[i]; }
};

const factor ZERO = factor();

factor operator+(const factor &a, const factor &b) {
  vector<int> c(303);
  for (int i = 0; i < 303; i++)
    c[i] = a.get(i) + b.get(i);
  return factor(c);
}

template<typename T>
class SegTree {
  int n;
  vector<T> seg;
  T nil;
  function<T(T,T)> binop;
  
  void update(int k, int l, int r, int p, T x) {
    if (p < l || r <= p) return;
    if (r - l == 1) seg[k] = x;
    else {
      update(2*k+1, l, (l+r)/2, p, x);
      update(2*k+2, (l+r)/2, r, p, x);
      seg[k] = binop(seg[2*k+1], seg[2*k+2]);
    }
  }
  T query(int k, int l, int r, int a, int b) {
    if (b <= l || r <= a) return nil;
    if (a <= l && r <= b) return seg[k];
    return binop(query(2*k+1, l, (l+r)/2, a, b), query(2*k+2, (l+r)/2, r, a, b));
  }
public:
  SegTree(int n, T nil, function<T(T, T)> binop): n(n), seg(4*n), nil(nil), binop(binop) {}
  void init() {
    for (int i = 0; i < 4*n; i++)
      seg[i] = nil;
  }
  // update p-th value to x
  void update(int p, T x) {
    update(0, 0, n, p, x);
  }
  // query for range [l, r)
  T query(int l, int r) {
    return query(0, 0, n, l, r);
  }
};

bool isprime(long long n) {
  if (n < 2) return false;
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  
  for (long long i = 3; i * i <= n; i += 2)
    if (n % i == 0)
      return false;
  
  return true;
}


int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  vector<int> primes;
  for (int i = 1; i <= 2000; i++)
    if (isprime(i))
      primes.push_back(i);

  int n;
  cin >> n;

  function<factor(factor,factor)> plus = [] (factor a, factor b) { return a + b; };
  SegTree tree(n, ZERO, plus);
  
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    vector<int> p(303);
    for (int j = 0; j < 303; j++) {
      while (a % primes[j] == 0) {
        a /= primes[j];
        ++p[j];
      }
    }
    tree.update(i, factor(p));
  }

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long p;
    int l, r;
    cin >> p >> l >> r;
    factor x = tree.query(l-1, r);
    bool ck = true;
    for (int j = 0; j < 303; j++) {
      int c = 0;
      while (p % primes[j] == 0) {
        ++c;
        p /= primes[j];
      }
      if (c > x.get(j)) {
        ck = false;
        break;
      }
    }

    if (ck)
      cout << "Yes" << endl;
    else
      cout << "NO" << endl;
  }
  
  return 0;
}
0