結果

問題 No.854 公平なりんご分配
ユーザー 0w10w1
提出日時 2019-07-31 20:17:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 423 ms / 3,153 ms
コード長 1,606 bytes
コンパイル時間 2,425 ms
コンパイル使用メモリ 206,644 KB
実行使用メモリ 126,320 KB
最終ジャッジ日時 2023-09-18 16:38:16
合計ジャッジ時間 12,667 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,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 5 ms
4,480 KB
testcase_27 AC 3 ms
4,432 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 5 ms
4,380 KB
testcase_32 AC 37 ms
29,116 KB
testcase_33 AC 44 ms
17,140 KB
testcase_34 AC 78 ms
38,928 KB
testcase_35 AC 55 ms
31,404 KB
testcase_36 AC 40 ms
4,840 KB
testcase_37 AC 35 ms
27,584 KB
testcase_38 AC 27 ms
22,868 KB
testcase_39 AC 125 ms
41,388 KB
testcase_40 AC 52 ms
15,000 KB
testcase_41 AC 56 ms
25,728 KB
testcase_42 AC 68 ms
38,400 KB
testcase_43 AC 87 ms
27,012 KB
testcase_44 AC 89 ms
36,008 KB
testcase_45 AC 92 ms
9,324 KB
testcase_46 AC 118 ms
35,328 KB
testcase_47 AC 42 ms
21,056 KB
testcase_48 AC 62 ms
37,828 KB
testcase_49 AC 57 ms
38,936 KB
testcase_50 AC 32 ms
27,320 KB
testcase_51 AC 117 ms
36,772 KB
testcase_52 AC 84 ms
17,764 KB
testcase_53 AC 44 ms
17,508 KB
testcase_54 AC 82 ms
20,584 KB
testcase_55 AC 28 ms
17,680 KB
testcase_56 AC 25 ms
18,296 KB
testcase_57 AC 42 ms
15,392 KB
testcase_58 AC 83 ms
8,176 KB
testcase_59 AC 22 ms
13,804 KB
testcase_60 AC 56 ms
15,524 KB
testcase_61 AC 30 ms
5,440 KB
testcase_62 AC 67 ms
13,320 KB
testcase_63 AC 51 ms
14,072 KB
testcase_64 AC 19 ms
7,344 KB
testcase_65 AC 47 ms
33,860 KB
testcase_66 AC 40 ms
10,684 KB
testcase_67 AC 65 ms
22,840 KB
testcase_68 AC 68 ms
11,564 KB
testcase_69 AC 42 ms
41,268 KB
testcase_70 AC 24 ms
15,176 KB
testcase_71 AC 29 ms
16,308 KB
testcase_72 AC 55 ms
4,916 KB
testcase_73 AC 39 ms
27,856 KB
testcase_74 AC 80 ms
33,400 KB
testcase_75 AC 42 ms
16,556 KB
testcase_76 AC 66 ms
26,604 KB
testcase_77 AC 68 ms
37,616 KB
testcase_78 AC 86 ms
12,596 KB
testcase_79 AC 79 ms
23,296 KB
testcase_80 AC 76 ms
24,636 KB
testcase_81 AC 55 ms
25,768 KB
testcase_82 AC 284 ms
126,056 KB
testcase_83 AC 388 ms
126,052 KB
testcase_84 AC 389 ms
125,980 KB
testcase_85 AC 330 ms
74,512 KB
testcase_86 AC 163 ms
6,344 KB
testcase_87 AC 285 ms
125,940 KB
testcase_88 AC 290 ms
126,068 KB
testcase_89 AC 286 ms
126,180 KB
testcase_90 AC 288 ms
126,320 KB
testcase_91 AC 283 ms
125,936 KB
testcase_92 AC 423 ms
126,004 KB
testcase_93 AC 421 ms
126,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  int maxa = *max_element(A.begin(), A.end());

  vector<int> zps; // zero positions
  for (int i = 0; i < N; ++i) {
    if (A[i] == 0) zps.push_back(i);
  }

  vector<int> apf; // any prime factor
  vector<int> prs;
  vector<int> pfx; {
    apf.resize(maxa + 1);
    iota(apf.begin(), apf.end(), 0);
    for (int i = 2; i < maxa + 1; ++i) {
      if (apf[i] != i) continue; // not prime
      prs.push_back(i);
      for (int j = i; j < maxa + 1; j += i) {
        apf[j] = i;
      }
    }
    pfx.resize(maxa + 1);
    for (int i = 0; i < prs.size(); ++i) {
      pfx[prs[i]] = i;
    }
  }

  vector<vector<int>> ap(N + 1, vector<int>(prs.size())); {
    for (int i = 0; i < N; ++i) {
      ap[i + 1] = ap[i];
      int v = A[i];
      while (1 < v) {
        ++ap[i + 1][pfx[apf[v]]];
        v /= apf[v];
      }
    }
  }

  int Q;
  cin >> Q;

  for (int qi = 0; qi < Q; ++qi) {
    int P, L, R;
    cin >> P >> L >> R;
    int zp = lower_bound(zps.begin(), zps.end(), L - 1) - zps.begin();
    if (zp < zps.size() && zps[zp] < R) {
      cout << "Yes" << endl;
    } else {
      bool ok = true;
      for (int p : prs) {
        if (P % p) continue;
        int c = 0;
        for (; P % p == 0; ++c) P /= p;
        if (ap[R][pfx[p]] - ap[L - 1][pfx[p]] < c) {
          ok = false;
          break;
        }
      }
      ok &= P == 1;
      cout << (ok ? "Yes" : "NO") << endl;
    }
  }

  return 0;
}

0