結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
81,532 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 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 TLE -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 TLE -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
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;

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);

  int n;
  cin >> n;

  vector<int> primes;
  vector<SegTree<short> > trees;

  for (int i = 1; i <= 2000; i++) {
    if (isprime(i)) {
      primes.push_back(i);
      auto plus = [](short a, short b) { return min(100, a + b); };
      trees.push_back(SegTree<short>(n, 0, plus));      
    }
  }

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    for (int j = 0; j < primes.size(); j++) {
      int c = 0;
      while (a % primes[j] == 0) {
        a /= primes[j];
        ++c;
      }
      trees[j].update(i, c);
    }
  }

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, l, r;
    cin >> x >> l >> r;

    bool ck = true;
    for (int j = 0; j < primes.size(); j++) {
      int c = 0;
      while (x % primes[j] == 0) {
        ++c;
        x /= primes[j];
      }
      if (c > trees[j].query(l-1, r)) {
        ck = false;
        break;
      }
    }

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

  return 0;
}
0