結果

問題 No.854 公平なりんご分配
ユーザー risujirohrisujiroh
提出日時 2019-07-26 22:13:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 891 ms / 3,153 ms
コード長 1,753 bytes
コンパイル時間 3,615 ms
コンパイル使用メモリ 179,204 KB
実行使用メモリ 122,368 KB
最終ジャッジ日時 2023-09-15 01:54:18
合計ジャッジ時間 11,661 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 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 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,528 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 3 ms
4,624 KB
testcase_27 AC 3 ms
4,572 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 3 ms
4,416 KB
testcase_32 AC 35 ms
28,508 KB
testcase_33 AC 24 ms
16,876 KB
testcase_34 AC 55 ms
38,048 KB
testcase_35 AC 41 ms
30,656 KB
testcase_36 AC 14 ms
5,020 KB
testcase_37 AC 34 ms
26,980 KB
testcase_38 AC 28 ms
22,512 KB
testcase_39 AC 70 ms
40,188 KB
testcase_40 AC 26 ms
14,876 KB
testcase_41 AC 35 ms
25,188 KB
testcase_42 AC 53 ms
37,476 KB
testcase_43 AC 46 ms
26,220 KB
testcase_44 AC 55 ms
34,936 KB
testcase_45 AC 30 ms
9,452 KB
testcase_46 AC 62 ms
34,448 KB
testcase_47 AC 28 ms
20,628 KB
testcase_48 AC 49 ms
36,916 KB
testcase_49 AC 49 ms
37,824 KB
testcase_50 AC 31 ms
26,800 KB
testcase_51 AC 61 ms
36,224 KB
testcase_52 AC 33 ms
17,568 KB
testcase_53 AC 24 ms
17,400 KB
testcase_54 AC 35 ms
20,260 KB
testcase_55 AC 20 ms
17,412 KB
testcase_56 AC 22 ms
18,212 KB
testcase_57 AC 23 ms
15,424 KB
testcase_58 AC 27 ms
8,304 KB
testcase_59 AC 15 ms
13,700 KB
testcase_60 AC 25 ms
15,264 KB
testcase_61 AC 10 ms
5,540 KB
testcase_62 AC 26 ms
13,416 KB
testcase_63 AC 22 ms
14,128 KB
testcase_64 AC 10 ms
7,444 KB
testcase_65 AC 42 ms
33,232 KB
testcase_66 AC 18 ms
10,844 KB
testcase_67 AC 36 ms
22,476 KB
testcase_68 AC 26 ms
11,440 KB
testcase_69 AC 50 ms
40,404 KB
testcase_70 AC 20 ms
15,112 KB
testcase_71 AC 20 ms
16,120 KB
testcase_72 AC 16 ms
5,092 KB
testcase_73 AC 34 ms
27,288 KB
testcase_74 AC 47 ms
32,676 KB
testcase_75 AC 22 ms
16,212 KB
testcase_76 AC 36 ms
26,152 KB
testcase_77 AC 49 ms
36,764 KB
testcase_78 AC 29 ms
12,412 KB
testcase_79 AC 37 ms
23,028 KB
testcase_80 AC 37 ms
24,268 KB
testcase_81 AC 35 ms
25,124 KB
testcase_82 AC 180 ms
122,364 KB
testcase_83 AC 237 ms
122,340 KB
testcase_84 AC 891 ms
122,164 KB
testcase_85 AC 202 ms
122,320 KB
testcase_86 AC 143 ms
122,328 KB
testcase_87 AC 183 ms
122,336 KB
testcase_88 AC 179 ms
122,340 KB
testcase_89 AC 180 ms
122,160 KB
testcase_90 AC 179 ms
122,360 KB
testcase_91 AC 180 ms
122,232 KB
testcase_92 AC 231 ms
122,368 KB
testcase_93 AC 248 ms
122,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

V<> sieve(int n) {
  V<bool> b((n + 1) / 3, true);
  V<> res{2, 3};
  for (int p = 5, d = 2; p * p < n; p += d, d = 6 - d) if (b[p / 3]) {
    for (int i = 5 * p, d = 2 * p; i < n; i += d, d = 6 * p - d) b[i / 3] = false;
  }
  for (int p = 5, d = 2; p < n; p += d, d = 6 - d) if(b[p / 3]) res.push_back(p);
  while (!res.empty() and res.back() >= n) res.pop_back();
  return res;
}

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

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> p2i(2000);
  {
    auto ps = sieve(2000);
    for (int i = 0; i < 303; ++i) {
      p2i[ps[i]] = i;
    }
  }
  VV<> a(303, V<>(n + 1));
  V<> z(n + 1);
  for (int i = 0; i < n; ++i) {
    int x; cin >> x;
    if (!x) {
      z[i] = 1;
      continue;
    }
    for (const auto& e : factorize(x)) {
      a[p2i[e.first]][i] = e.second;
    }
  }
  for (auto&& v : a) {
    for (int i = n - 1; i >= 0; --i) v[i] += v[i + 1];
  }
  for (int i = n - 1; i >= 0; --i) z[i] += z[i + 1];

  int q; cin >> q;
  while (q--) {
    int p, l, r; cin >> p >> l >> r, --l;
    if (z[l] - z[r]) cout << "Yes" << '\n';
    else {
      bool ok = true;
      for (const auto& e : factorize(p)) {
        if (e.first > 2000) {
          ok = false;
          break;
        }
        int i = p2i[e.first];
        if (e.second > a[i][l] - a[i][r]) {
          ok = false;
          break;
        }
      }
      cout << (ok ? "Yes" : "NO") << '\n';
    }
  }
}
0