結果

問題 No.854 公平なりんご分配
ユーザー kk
提出日時 2021-03-20 20:34:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,419 ms / 3,153 ms
コード長 1,624 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 213,120 KB
実行使用メモリ 123,060 KB
最終ジャッジ日時 2023-08-13 14:30:41
合計ジャッジ時間 26,485 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,376 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,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 7 ms
4,396 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 5 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 6 ms
4,380 KB
testcase_32 AC 76 ms
28,372 KB
testcase_33 AC 98 ms
16,476 KB
testcase_34 AC 200 ms
38,220 KB
testcase_35 AC 130 ms
30,468 KB
testcase_36 AC 48 ms
4,740 KB
testcase_37 AC 74 ms
26,756 KB
testcase_38 AC 53 ms
22,260 KB
testcase_39 AC 352 ms
40,292 KB
testcase_40 AC 105 ms
14,612 KB
testcase_41 AC 134 ms
25,024 KB
testcase_42 AC 167 ms
37,356 KB
testcase_43 AC 235 ms
26,040 KB
testcase_44 AC 243 ms
35,012 KB
testcase_45 AC 134 ms
9,268 KB
testcase_46 AC 337 ms
34,400 KB
testcase_47 AC 96 ms
20,520 KB
testcase_48 AC 148 ms
36,788 KB
testcase_49 AC 135 ms
37,632 KB
testcase_50 AC 64 ms
26,864 KB
testcase_51 AC 333 ms
35,984 KB
testcase_52 AC 239 ms
17,320 KB
testcase_53 AC 123 ms
16,992 KB
testcase_54 AC 240 ms
19,960 KB
testcase_55 AC 80 ms
17,352 KB
testcase_56 AC 54 ms
17,768 KB
testcase_57 AC 95 ms
14,916 KB
testcase_58 AC 119 ms
7,824 KB
testcase_59 AC 45 ms
13,588 KB
testcase_60 AC 144 ms
14,860 KB
testcase_61 AC 42 ms
5,192 KB
testcase_62 AC 142 ms
13,008 KB
testcase_63 AC 136 ms
13,856 KB
testcase_64 AC 29 ms
7,016 KB
testcase_65 AC 113 ms
33,096 KB
testcase_66 AC 76 ms
10,724 KB
testcase_67 AC 195 ms
22,272 KB
testcase_68 AC 145 ms
11,216 KB
testcase_69 AC 84 ms
40,264 KB
testcase_70 AC 58 ms
14,984 KB
testcase_71 AC 71 ms
16,004 KB
testcase_72 AC 67 ms
4,944 KB
testcase_73 AC 103 ms
27,020 KB
testcase_74 AC 274 ms
32,672 KB
testcase_75 AC 100 ms
15,968 KB
testcase_76 AC 230 ms
26,028 KB
testcase_77 AC 224 ms
36,836 KB
testcase_78 AC 179 ms
12,284 KB
testcase_79 AC 245 ms
22,892 KB
testcase_80 AC 226 ms
24,228 KB
testcase_81 AC 173 ms
24,904 KB
testcase_82 AC 513 ms
122,960 KB
testcase_83 AC 521 ms
122,880 KB
testcase_84 AC 519 ms
123,060 KB
testcase_85 AC 546 ms
122,908 KB
testcase_86 AC 446 ms
122,928 KB
testcase_87 AC 1,419 ms
122,924 KB
testcase_88 AC 1,392 ms
122,892 KB
testcase_89 AC 1,402 ms
122,852 KB
testcase_90 AC 1,401 ms
123,060 KB
testcase_91 AC 1,407 ms
122,892 KB
testcase_92 AC 1,413 ms
123,056 KB
testcase_93 AC 1,382 ms
123,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

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> a(n);
  vector<int> zeros(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    zeros[i+1] = zeros[i] + (a[i] == 0);
  }
  
  vector<vector<int> > factors;
  vector<int> primes;
  
  for (int p = 0; p < 2000; p++) {
    if (isprime(p)) {
      primes.push_back(p);
      vector<int> f(n+1);
      for (int i = 0; i < n; i++) {
        int b = a[i];
        f[i+1] += f[i];
        while (b > 0 && b % p == 0) {
          b /= p;
          ++f[i+1];
        }

      }
      factors.push_back(f);
    }
  }

  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) {
        x /= primes[j];
        ++c;
      }
      if (c > factors[j][r] - factors[j][l-1]) {
        ck = false;
        break;
      }
    }
    ck &= x == 1;
    ck |= zeros[r] - zeros[l-1] > 0;
    if (ck)
      cout << "Yes" << endl;
    else
      cout << "NO" << endl;
  }
  
  return 0;
}
0