結果

問題 No.854 公平なりんご分配
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-07-26 21:52:52
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 1,832 ms / 3,153 ms
コード長 2,934 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 107,136 KB
実行使用メモリ 133,828 KB
最終ジャッジ日時 2023-09-04 01:57:50
合計ジャッジ時間 20,997 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 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,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 4 ms
4,384 KB
testcase_23 AC 5 ms
4,384 KB
testcase_24 AC 7 ms
4,880 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 8 ms
5,116 KB
testcase_27 AC 6 ms
4,876 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 7 ms
4,376 KB
testcase_32 AC 92 ms
30,244 KB
testcase_33 AC 157 ms
20,076 KB
testcase_34 AC 279 ms
40,564 KB
testcase_35 AC 175 ms
32,864 KB
testcase_36 AC 67 ms
6,960 KB
testcase_37 AC 94 ms
28,496 KB
testcase_38 AC 64 ms
22,984 KB
testcase_39 AC 505 ms
42,688 KB
testcase_40 AC 205 ms
16,052 KB
testcase_41 AC 195 ms
25,844 KB
testcase_42 AC 228 ms
41,364 KB
testcase_43 AC 371 ms
27,476 KB
testcase_44 AC 347 ms
36,940 KB
testcase_45 AC 212 ms
11,212 KB
testcase_46 AC 494 ms
37,136 KB
testcase_47 AC 149 ms
22,756 KB
testcase_48 AC 198 ms
38,252 KB
testcase_49 AC 172 ms
39,748 KB
testcase_50 AC 78 ms
28,476 KB
testcase_51 AC 454 ms
37,192 KB
testcase_52 AC 236 ms
18,924 KB
testcase_53 AC 92 ms
19,596 KB
testcase_54 AC 229 ms
22,764 KB
testcase_55 AC 49 ms
19,096 KB
testcase_56 AC 50 ms
19,616 KB
testcase_57 AC 113 ms
16,116 KB
testcase_58 AC 143 ms
9,068 KB
testcase_59 AC 40 ms
14,520 KB
testcase_60 AC 142 ms
17,516 KB
testcase_61 AC 39 ms
6,172 KB
testcase_62 AC 146 ms
15,200 KB
testcase_63 AC 80 ms
15,264 KB
testcase_64 AC 31 ms
8,560 KB
testcase_65 AC 105 ms
34,844 KB
testcase_66 AC 81 ms
13,228 KB
testcase_67 AC 152 ms
24,008 KB
testcase_68 AC 120 ms
14,448 KB
testcase_69 AC 77 ms
41,308 KB
testcase_70 AC 46 ms
16,048 KB
testcase_71 AC 52 ms
17,788 KB
testcase_72 AC 90 ms
6,524 KB
testcase_73 AC 68 ms
29,988 KB
testcase_74 AC 185 ms
35,180 KB
testcase_75 AC 109 ms
19,056 KB
testcase_76 AC 113 ms
28,460 KB
testcase_77 AC 126 ms
38,244 KB
testcase_78 AC 253 ms
13,976 KB
testcase_79 AC 211 ms
24,788 KB
testcase_80 AC 205 ms
26,176 KB
testcase_81 AC 103 ms
26,176 KB
testcase_82 AC 312 ms
133,300 KB
testcase_83 AC 678 ms
133,096 KB
testcase_84 AC 677 ms
133,828 KB
testcase_85 AC 696 ms
133,420 KB
testcase_86 AC 209 ms
125,864 KB
testcase_87 AC 307 ms
125,648 KB
testcase_88 AC 312 ms
131,948 KB
testcase_89 AC 312 ms
126,844 KB
testcase_90 AC 310 ms
133,352 KB
testcase_91 AC 309 ms
131,728 KB
testcase_92 AC 1,832 ms
131,740 KB
testcase_93 AC 1,827 ms
130,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum LIM = 2005;

int N;
int[] A;
int Q;
int[] M, L, R;

void main() {
  auto isnp = new bool[LIM];
  foreach (p; 2 .. LIM) {
    if (!isnp[p]) {
      for (int n = 2 * p; n < LIM; n += p) {
        isnp[n] = true;
      }
    }
  }
  int[] primes;
  foreach (p; 2 .. LIM) {
    if (!isnp[p]) {
      primes ~= p;
    }
  }
  stderr.writeln("|primes| = ", primes.length);
  const primesLen = cast(int)(primes.length);
  
  try {
    for (; ; ) {
      N = readInt();
      A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }
      Q = readInt();
      M = new int[Q];
      L = new int[Q];
      R = new int[Q];
      foreach (q; 0 .. Q) {
        M[q] = readInt();
        L[q] = readInt() - 1;
        R[q] = readInt();
      }
      
      auto zero = new int[N + 1];
      foreach (i; 0 .. N) {
        zero[i + 1] = zero[i] + ((A[i] == 0) ? 1 : 0);
      }
      
      auto sums = new int[][](primesLen, N + 1);
      foreach (h; 0 .. primesLen) {
        const p = primes[h];
        foreach (i; 0 .. N) {
          int e;
          if (A[i] != 0) {
            for (int a = A[i]; a % p == 0; a /= p) {
              ++e;
            }
          }
          sums[h][i + 1] = sums[h][i] + e;
        }
      }
      
      foreach (q; 0 .. Q) {
        bool ans;
        if (zero[R[q]] - zero[L[q]] > 0) {
          ans = true;
        } else {
          ans = true;
          int m = M[q];
          foreach (h; 0 .. primesLen) {
            const p = primes[h];
            int e;
            for (; m % p == 0; m /= p) {
              ++e;
            }
            ans = ans && (sums[h][R[q]] - sums[h][L[q]] >= e);
          }
          ans = ans && (m == 1);
        }
        writeln(ans ? "Yes" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}
0