結果

問題 No.854 公平なりんご分配
ユーザー kk
提出日時 2021-03-20 19:33:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,400 bytes
コンパイル時間 3,038 ms
コンパイル使用メモリ 225,580 KB
実行使用メモリ 77,184 KB
最終ジャッジ日時 2024-05-01 06:41:28
合計ジャッジ時間 14,058 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,880 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 4 ms
6,940 KB
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 5 ms
6,940 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 6 ms
6,940 KB
testcase_27 AC 5 ms
6,944 KB
testcase_28 AC 4 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 3 ms
6,940 KB
testcase_31 AC 6 ms
6,940 KB
testcase_32 AC 70 ms
54,016 KB
testcase_33 AC 62 ms
30,080 KB
testcase_34 AC 124 ms
72,448 KB
testcase_35 AC 90 ms
57,856 KB
testcase_36 AC 46 ms
6,940 KB
testcase_37 AC 60 ms
50,560 KB
testcase_38 AC 44 ms
41,344 KB
testcase_39 AC 171 ms
77,184 KB
testcase_40 AC 73 ms
26,240 KB
testcase_41 AC 85 ms
46,976 KB
testcase_42 AC 110 ms
72,448 KB
testcase_43 AC 121 ms
49,408 KB
testcase_44 AC 130 ms
66,176 KB
testcase_45 AC 103 ms
15,360 KB
testcase_46 AC 158 ms
66,304 KB
testcase_47 AC 64 ms
37,632 KB
testcase_48 AC 97 ms
71,040 KB
testcase_49 AC 99 ms
72,320 KB
testcase_50 AC 61 ms
50,432 KB
testcase_51 AC 157 ms
68,608 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 TLE -
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;
}

map<long long, int> factorize(long long n) {
  map<long long, int> ret;
  
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++ret[i];
      n /= i;
    }
  }
  
  if (n != 1)
    ret[n] = 1;
  
  return ret;
}

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

  int n;
  cin >> n;
  
  vector<int> index(2000);
  vector<SegTree<short> > trees;

  for (int i = 1; i <= 2000; i++) {
    if (isprime(i)) {
      index[i] = trees.size();
      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;
    auto fs = factorize(a);
    for (auto &[k, v] :fs) {
      trees[index[k]].update(i, v);
    }
  }

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

    auto fs = factorize(x);
    bool ck = true;

    for (auto &[k, v]: fs) {
      if (k > 2000) {
        ck = false;
        break;
      }
      if (v > trees[index[k]].query(l-1, r)) {
        ck = false;
        break;
      }
    }

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

  return 0;
}
0