結果

問題 No.854 公平なりんご分配
ユーザー そすうぽよそすうぽよ
提出日時 2019-07-26 22:51:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,613 ms / 3,153 ms
コード長 1,381 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 207,040 KB
実行使用メモリ 122,912 KB
最終ジャッジ日時 2023-09-15 03:29:24
合計ジャッジ時間 24,121 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 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,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 4 ms
4,384 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 7 ms
4,568 KB
testcase_25 AC 4 ms
4,384 KB
testcase_26 AC 8 ms
4,560 KB
testcase_27 AC 5 ms
4,840 KB
testcase_28 AC 5 ms
4,384 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 4 ms
4,384 KB
testcase_31 AC 7 ms
4,540 KB
testcase_32 AC 87 ms
28,488 KB
testcase_33 AC 125 ms
16,608 KB
testcase_34 AC 242 ms
37,816 KB
testcase_35 AC 158 ms
30,540 KB
testcase_36 AC 69 ms
4,992 KB
testcase_37 AC 86 ms
26,900 KB
testcase_38 AC 63 ms
22,288 KB
testcase_39 AC 424 ms
40,036 KB
testcase_40 AC 147 ms
14,632 KB
testcase_41 AC 170 ms
24,876 KB
testcase_42 AC 194 ms
37,208 KB
testcase_43 AC 289 ms
25,936 KB
testcase_44 AC 290 ms
34,804 KB
testcase_45 AC 198 ms
9,036 KB
testcase_46 AC 415 ms
34,176 KB
testcase_47 AC 124 ms
20,752 KB
testcase_48 AC 179 ms
36,540 KB
testcase_49 AC 166 ms
37,332 KB
testcase_50 AC 79 ms
26,828 KB
testcase_51 AC 406 ms
35,936 KB
testcase_52 AC 223 ms
17,404 KB
testcase_53 AC 95 ms
17,144 KB
testcase_54 AC 224 ms
19,968 KB
testcase_55 AC 57 ms
16,956 KB
testcase_56 AC 53 ms
17,844 KB
testcase_57 AC 110 ms
14,892 KB
testcase_58 AC 165 ms
7,900 KB
testcase_59 AC 45 ms
13,360 KB
testcase_60 AC 149 ms
15,024 KB
testcase_61 AC 47 ms
5,768 KB
testcase_62 AC 172 ms
13,104 KB
testcase_63 AC 102 ms
13,580 KB
testcase_64 AC 35 ms
6,976 KB
testcase_65 AC 107 ms
33,268 KB
testcase_66 AC 87 ms
10,480 KB
testcase_67 AC 164 ms
22,360 KB
testcase_68 AC 140 ms
11,204 KB
testcase_69 AC 83 ms
40,144 KB
testcase_70 AC 49 ms
14,632 KB
testcase_71 AC 57 ms
15,688 KB
testcase_72 AC 94 ms
5,172 KB
testcase_73 AC 79 ms
27,352 KB
testcase_74 AC 191 ms
32,324 KB
testcase_75 AC 109 ms
16,084 KB
testcase_76 AC 137 ms
26,068 KB
testcase_77 AC 143 ms
36,676 KB
testcase_78 AC 217 ms
12,064 KB
testcase_79 AC 209 ms
22,880 KB
testcase_80 AC 196 ms
24,136 KB
testcase_81 AC 117 ms
25,236 KB
testcase_82 AC 531 ms
122,612 KB
testcase_83 AC 756 ms
122,684 KB
testcase_84 AC 723 ms
122,736 KB
testcase_85 AC 749 ms
122,668 KB
testcase_86 AC 508 ms
122,608 KB
testcase_87 AC 533 ms
122,912 KB
testcase_88 AC 536 ms
122,684 KB
testcase_89 AC 530 ms
122,884 KB
testcase_90 AC 527 ms
122,560 KB
testcase_91 AC 537 ms
122,680 KB
testcase_92 AC 1,613 ms
122,604 KB
testcase_93 AC 1,586 ms
122,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

vecint pl(int n) {
  vector<bool> b(n+1, true);
  b[0] = b[1] = false;
  for (int i = 2; i*i <= n; ++i)
    if (b[i])
      for (int j = i*i; j <= n; j += i)
        b[j] = false;
  vecint res;
  REP(i,n+1)
    if (b[i])
      res.push_back(i);
  return res;
}

int main()
{
  int n;
  cin>>n;
  vector<vecint> v(304, vecint(n+1, 0));
  auto pp = pl(2000);
  int np = pp.size();
  REP(i,n) {
    int b;
    cin>>b;
    if (b == 0) {
      v[303][i+1] = v[303][i] + 1;
      REP(j,np) {
        v[j][i+1] = v[j][i];
      }
    } else {
      v[303][i+1] = v[303][i];
      REP(j,np) {
        v[j][i+1] = v[j][i];
        while ((b % pp[j]) == 0) {
          b /= pp[j];
          ++v[j][i+1];
        }
      }
    }
  }
  int q;
  cin>>q;
  REP(i,q) {
    int p,l,r;
    cin>>p>>l>>r;
    if (v[303][r] - v[303][l-1] > 0) {
      cout << "Yes" << endl;
      continue;
    }
    REP(j,np) {
      int d = v[j][r] - v[j][l-1];
      REP(k,d) {
        if ((p % pp[j]) == 0) {
          p /= pp[j];
        } else {
          break;
        }
      }
    }
    if (p == 1) {
      cout << "Yes" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
0