結果

問題 No.854 公平なりんご分配
ユーザー MayimgMayimg
提出日時 2019-07-27 04:11:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 576 ms / 3,153 ms
コード長 1,491 bytes
コンパイル時間 2,532 ms
コンパイル使用メモリ 208,484 KB
実行使用メモリ 243,492 KB
最終ジャッジ日時 2023-09-15 05:43:49
合計ジャッジ時間 15,689 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 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,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 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,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 4 ms
4,832 KB
testcase_24 AC 6 ms
5,632 KB
testcase_25 AC 3 ms
4,604 KB
testcase_26 AC 6 ms
5,716 KB
testcase_27 AC 6 ms
5,828 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 3 ms
4,388 KB
testcase_31 AC 6 ms
5,600 KB
testcase_32 AC 82 ms
53,968 KB
testcase_33 AC 63 ms
30,368 KB
testcase_34 AC 135 ms
73,188 KB
testcase_35 AC 100 ms
58,148 KB
testcase_36 AC 33 ms
6,628 KB
testcase_37 AC 77 ms
50,900 KB
testcase_38 AC 62 ms
41,776 KB
testcase_39 AC 176 ms
77,492 KB
testcase_40 AC 66 ms
26,396 KB
testcase_41 AC 89 ms
47,096 KB
testcase_42 AC 127 ms
71,900 KB
testcase_43 AC 119 ms
49,168 KB
testcase_44 AC 140 ms
66,856 KB
testcase_45 AC 85 ms
15,592 KB
testcase_46 AC 165 ms
65,800 KB
testcase_47 AC 71 ms
37,944 KB
testcase_48 AC 122 ms
70,832 KB
testcase_49 AC 119 ms
72,544 KB
testcase_50 AC 74 ms
50,292 KB
testcase_51 AC 163 ms
69,284 KB
testcase_52 AC 83 ms
31,820 KB
testcase_53 AC 56 ms
31,304 KB
testcase_54 AC 88 ms
37,124 KB
testcase_55 AC 48 ms
31,728 KB
testcase_56 AC 50 ms
32,956 KB
testcase_57 AC 54 ms
27,144 KB
testcase_58 AC 70 ms
13,320 KB
testcase_59 AC 37 ms
24,052 KB
testcase_60 AC 64 ms
27,308 KB
testcase_61 AC 22 ms
7,892 KB
testcase_62 AC 68 ms
23,356 KB
testcase_63 AC 50 ms
24,596 KB
testcase_64 AC 21 ms
11,584 KB
testcase_65 AC 98 ms
63,664 KB
testcase_66 AC 42 ms
18,308 KB
testcase_67 AC 81 ms
41,776 KB
testcase_68 AC 55 ms
19,504 KB
testcase_69 AC 111 ms
77,748 KB
testcase_70 AC 41 ms
26,908 KB
testcase_71 AC 46 ms
29,056 KB
testcase_72 AC 43 ms
6,824 KB
testcase_73 AC 76 ms
51,348 KB
testcase_74 AC 113 ms
62,432 KB
testcase_75 AC 57 ms
29,096 KB
testcase_76 AC 83 ms
48,956 KB
testcase_77 AC 114 ms
70,548 KB
testcase_78 AC 77 ms
21,448 KB
testcase_79 AC 91 ms
42,856 KB
testcase_80 AC 92 ms
45,268 KB
testcase_81 AC 78 ms
47,072 KB
testcase_82 AC 367 ms
243,168 KB
testcase_83 AC 508 ms
243,216 KB
testcase_84 AC 504 ms
243,224 KB
testcase_85 AC 538 ms
243,492 KB
testcase_86 AC 246 ms
243,288 KB
testcase_87 AC 366 ms
243,216 KB
testcase_88 AC 364 ms
243,216 KB
testcase_89 AC 363 ms
243,264 KB
testcase_90 AC 364 ms
243,272 KB
testcase_91 AC 363 ms
243,284 KB
testcase_92 AC 575 ms
243,300 KB
testcase_93 AC 576 ms
243,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> sieve(int n) {
  vector<int> primes;
  vector<bool> is_prime(n + 1, 1);
  is_prime[0] = 0;
  is_prime[1] = 0;
  for (int i = 2; i <= n; i++) {
    if (!is_prime[i]) continue;
    primes.push_back(i);
    for (int j = i + i; j <= n; j += i) {
      is_prime[j] = 0;
    }
  }
  return primes;
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  vector<int> primes = sieve(2000);
  int n;
  cin >> n;
  int m = (int) primes.size();
  vector<vector<long long>> cnt(n + 1, vector<long long>(m));
  vector<int> zero(n + 1);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    vector<int> tmp(m);
    if (a == 0) {
      zero[i + 1] = zero[i] + 1;
    } else {
      zero[i + 1] = zero[i];
      for (int j = 0; j < m; j++) {
        int c = 0;
        while (a % primes[j] == 0) {
          a /= primes[j];
          c++;
        }
        tmp[j] = c;
      }
    }
    for (int j = 0; j < m; j++) {
      cnt[i + 1][j] = cnt[i][j] + tmp[j];
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int p, l, r;
    cin >> p >> l >> r;
    if (zero[l - 1] != zero[r]) {
      puts("Yes");
      continue;
    } 
    bool ok = true;
    for (int j = 0; j < m; j++) {
      int c = 0;
      while (p % primes[j] == 0) {
        p /= primes[j];
        c++;
      }
      ok &= (c <= cnt[r][j] - cnt[l - 1][j]);
    }
    ok &= (p == 1);
    puts(ok ? "Yes" : "NO");
  }
  return 0;
}
0