結果

問題 No.854 公平なりんご分配
ユーザー cotton_fn_cotton_fn_
提出日時 2019-07-27 04:30:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,342 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 132,412 KB
実行使用メモリ 161,292 KB
最終ジャッジ日時 2023-09-15 05:47:21
合計ジャッジ時間 26,231 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
160,488 KB
testcase_01 AC 54 ms
160,532 KB
testcase_02 AC 53 ms
160,712 KB
testcase_03 AC 53 ms
160,544 KB
testcase_04 AC 52 ms
160,476 KB
testcase_05 AC 52 ms
160,472 KB
testcase_06 AC 52 ms
160,428 KB
testcase_07 AC 54 ms
160,656 KB
testcase_08 AC 53 ms
160,460 KB
testcase_09 AC 52 ms
160,424 KB
testcase_10 AC 52 ms
160,476 KB
testcase_11 AC 52 ms
160,468 KB
testcase_12 AC 53 ms
160,412 KB
testcase_13 AC 52 ms
160,464 KB
testcase_14 AC 53 ms
160,468 KB
testcase_15 AC 52 ms
160,632 KB
testcase_16 AC 53 ms
160,468 KB
testcase_17 AC 53 ms
160,748 KB
testcase_18 AC 53 ms
160,424 KB
testcase_19 AC 53 ms
160,696 KB
testcase_20 AC 53 ms
160,464 KB
testcase_21 AC 53 ms
160,476 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 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 WA -
testcase_83 AC 1,194 ms
161,164 KB
testcase_84 AC 1,201 ms
161,056 KB
testcase_85 AC 1,242 ms
160,972 KB
testcase_86 AC 281 ms
161,084 KB
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs


i64 n;
vector<array<int, 100001>> fs;
vector<int> zs;
int main() {
  cin >> n;
  vector<bool> serve(2001, true);
  for (int x = 2; x <= 2000; ++x) {
    if (serve[x]) {
      for (int y = 2 * x; y <= 2000; y += x) serve[y] = false;
    }
  }
  map<int, int> pmp, ipmp;
  for (int x = 2; x <= 2000; ++x) {
    if (serve[x]) {
      pmp[x] = pmp.size() + 1;
      ipmp[pmp.size()] = x;
    }
  }
  init_n(fs, 401);
  init_n(zs, n + 1);
  for (i64 i = 1; i <= n; ++i) {
    i64 a; cin >> a;
    if (a == 0) {
      zs[i]++;
      continue;
    }
    for (i64 x = 2; x <= 40; ++x) {
      while (a % x == 0) {
        fs[pmp[x]][i]++;
        a /= x;
      }
    }
    if (a > 1) fs[pmp[a]][i]++;
  }
  for (int k = 0; k <= 400; ++k) {
    for (int i = 1; i <= n; ++i) {
      fs[k][i] += fs[k][i - 1];
    }
  }
  for (int i = 1; i <= n; ++i) zs[i] += zs[i - 1];
  
  i64 q;
  cin >> q;
  while (q--) {
    i64 p, l, r;
    cin >> p >> l >> r;
    if (p == 1) {
      cout << "Yes\n";
      continue;
    }
    if (zs[r] - zs[l - 1] > 0) {
      cout << "NO\n";
      continue;
    }
    map<i64, i64> mp;
    for (int i = 1; i <= ipmp.size(); ++i) {
      i64 x = ipmp[i];
      while (p % x == 0) {
        mp[i]++;
        p /= x;
      }
    }
    bool ok = true;
    for (auto e : mp) {
      i64 i = e.first, c = e.second;
      i64 s = fs[i][r] - fs[i][l - 1];
      if (c > s) ok = false;
    }
    cout << (ok ? "Yes" : "NO") << '\n';
  }
  return 0;
}
0