結果
問題 | No.854 公平なりんご分配 |
ユーザー | bal4u |
提出日時 | 2019-07-27 12:32:39 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 92 ms / 3,153 ms |
コード長 | 4,572 bytes |
コンパイル時間 | 247 ms |
コンパイル使用メモリ | 34,668 KB |
実行使用メモリ | 100,772 KB |
最終ジャッジ日時 | 2024-07-02 10:53:12 |
合計ジャッジ時間 | 5,473 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
testcase_20 | AC | 1 ms
5,376 KB |
testcase_21 | AC | 1 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 3 ms
5,376 KB |
testcase_27 | AC | 3 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 21 ms
22,912 KB |
testcase_33 | AC | 15 ms
12,672 KB |
testcase_34 | AC | 34 ms
30,464 KB |
testcase_35 | AC | 25 ms
24,192 KB |
testcase_36 | AC | 8 ms
5,376 KB |
testcase_37 | AC | 20 ms
21,120 KB |
testcase_38 | AC | 16 ms
17,408 KB |
testcase_39 | AC | 42 ms
32,000 KB |
testcase_40 | AC | 16 ms
11,392 KB |
testcase_41 | AC | 24 ms
19,584 KB |
testcase_42 | AC | 32 ms
30,208 KB |
testcase_43 | AC | 28 ms
20,480 KB |
testcase_44 | AC | 34 ms
27,648 KB |
testcase_45 | AC | 18 ms
6,656 KB |
testcase_46 | AC | 39 ms
27,520 KB |
testcase_47 | AC | 18 ms
16,256 KB |
testcase_48 | AC | 30 ms
29,312 KB |
testcase_49 | AC | 30 ms
30,336 KB |
testcase_50 | AC | 19 ms
21,120 KB |
testcase_51 | AC | 39 ms
28,544 KB |
testcase_52 | AC | 34 ms
13,440 KB |
testcase_53 | AC | 17 ms
24,064 KB |
testcase_54 | AC | 22 ms
15,488 KB |
testcase_55 | AC | 12 ms
13,440 KB |
testcase_56 | AC | 14 ms
14,080 KB |
testcase_57 | AC | 14 ms
11,520 KB |
testcase_58 | AC | 15 ms
5,504 KB |
testcase_59 | AC | 10 ms
10,368 KB |
testcase_60 | AC | 16 ms
11,520 KB |
testcase_61 | AC | 6 ms
5,376 KB |
testcase_62 | AC | 17 ms
10,240 KB |
testcase_63 | AC | 13 ms
10,496 KB |
testcase_64 | AC | 6 ms
5,376 KB |
testcase_65 | AC | 25 ms
26,496 KB |
testcase_66 | AC | 12 ms
8,064 KB |
testcase_67 | AC | 20 ms
17,152 KB |
testcase_68 | AC | 14 ms
8,320 KB |
testcase_69 | AC | 28 ms
32,256 KB |
testcase_70 | AC | 11 ms
11,136 KB |
testcase_71 | AC | 12 ms
12,416 KB |
testcase_72 | AC | 10 ms
5,376 KB |
testcase_73 | AC | 20 ms
21,376 KB |
testcase_74 | AC | 29 ms
26,368 KB |
testcase_75 | AC | 14 ms
12,416 KB |
testcase_76 | AC | 23 ms
20,736 KB |
testcase_77 | AC | 29 ms
29,440 KB |
testcase_78 | AC | 19 ms
9,216 KB |
testcase_79 | AC | 24 ms
18,176 KB |
testcase_80 | AC | 24 ms
19,072 KB |
testcase_81 | AC | 20 ms
19,456 KB |
testcase_82 | AC | 55 ms
99,328 KB |
testcase_83 | AC | 54 ms
99,844 KB |
testcase_84 | AC | 54 ms
100,360 KB |
testcase_85 | AC | 23 ms
6,940 KB |
testcase_86 | AC | 8 ms
6,940 KB |
testcase_87 | AC | 59 ms
100,348 KB |
testcase_88 | AC | 59 ms
100,608 KB |
testcase_89 | AC | 58 ms
99,588 KB |
testcase_90 | AC | 60 ms
99,168 KB |
testcase_91 | AC | 59 ms
99,616 KB |
testcase_92 | AC | 92 ms
100,480 KB |
testcase_93 | AC | 92 ms
100,772 KB |
コンパイルメッセージ
main.c: In function 'in': main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration] 9 | #define gc() getchar_unlocked() | ^~~~~~~~~~~~~~~~ main.c:17:24: note: in expansion of macro 'gc' 17 | int n = 0, c = gc(); | ^~ main.c: In function 'outs': main.c:10:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration] 10 | #define pc(c) putchar_unlocked(c) | ^~~~~~~~~~~~~~~~ main.c:22:33: note: in expansion of macro 'pc' 22 | void outs(char *s) { while (*s) pc(*s++); pc('\n'); } | ^~
ソースコード
// yukicoder: No.854 公平なりんご分配 // 2019.7.27 bal4u #include <stdio.h> #include <string.h> #include <math.h> #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } void outs(char *s) { while (*s) pc(*s++); pc('\n'); } #define MAX 100005 #define SIZE 14 #define TBL 305 int id[2003]; int factor[50], power[50], sz; int sq[2003] = { 0,1 }; int ptbl[TBL] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997,1009,1013, 1019,1021,1031,1033,1039,1049,1051,1061,1063,1069, 1087,1091,1093,1097,1103,1109,1117,1123,1129,1151, 1153,1163,1171,1181,1187,1193,1201,1213,1217,1223, 1229,1231,1237,1249,1259,1277,1279,1283,1289,1291, 1297,1301,1303,1307,1319,1321,1327,1361,1367,1373, 1381,1399,1409,1423,1427,1429,1433,1439,1447,1451, 1453,1459,1471,1481,1483,1487,1489,1493,1499,1511, 1523,1531,1543,1549,1553,1559,1567,1571,1579,1583, 1597,1601,1607,1609,1613,1619,1621,1627,1637,1657, 1663,1667,1669,1693,1697,1699,1709,1721,1723,1733, 1741,1747,1753,1759,1777,1783,1787,1789,1801,1811, 1823,1831,1847,1861,1867,1871,1873,1877,1879,1889, 1901,1907,1913,1931,1933,1949,1951,1973,1979,1987, 1993,1997,1999 }; int prime_factor(int n) { int i, b, d, w; sz = 0, b = (int)sqrt((double)n); for (i = 1; n > 1; i++) { if ((d = ptbl[i]) == 0) break; if (d > b) break; if (n % d) continue; factor[sz] = d, w = 0; do n /= d, w++; while (n % d == 0); power[sz++] = w; } if (n >= 2003) return 0; if (n > 1) factor[sz] = n, power[sz++] = 1; return 1; } int bit[TBL][MAX], bitn; void add(int k, int i, int v) { while (i <= bitn) bit[k][i] += v, i += i & -i; } int sum(int k, int i) { int s = 0; while (i > 0) s += bit[k][i], i -= i & -i; return s; } void calc_prime(int k, int n) { int i, v, w, lim; lim = sq[n]; for (i = 1; n > 1 && (v = ptbl[i]) <= lim; i++) { if (n % v) continue; w = 0; do n /= v, w++; while (n % v == 0); add(i, k, w); } if (n > 1) add(id[n], k, 1); } int zero[MAX], zw; // a[i]>=key という条件を満たす最小のi int lower_bound(int x) { int m, l = 0, r = zw; while (l+1 < r) { m = (l+r)/2; if (zero[m] < x) l = m; else r = m; } return zero[l] < x? r: l; } // a[i]>key という条件を満たす最小のi int upper_bound(int l, int x) { int m, r = zw; while (l+1 < r) { m = (l+r)/2; if (zero[m] <= x) l = m; else r = m; } return zero[l] <= x? r: l; } #define SQ2000 44 // sqrt(2000) int main() { int i, k, Q, ans, _P, _L, _R; // 初期化処理 k = 1; for (i = 1; i <= SQ2000; i++) while (k < i*i) sq[k++] = i-1; i--; while (k <= 2000) sq[k++] = i; for (i = 1; i < TBL; i++) id[ptbl[i]] = i; // 入力を素因数分解して、BIT木にしまう bitn = in(); for (i = 1; i <= bitn; i++) { int a = in(); if (a) calc_prime(i, a); else zero[zw++] = i; } Q = in(); _P = -1; while (Q--) { int P = in(), L = in(), R = in(); if (P == _P && L == _L && R == _R) goto done; _P = P, _L = L, _R = R; ans = 1; if (P == 1) goto done; // ひとり(P=1)だけに分けるケース if (zw) { // zero (0) が [L,R] に存在するケース k = lower_bound(L); if (upper_bound(k, R) >= k+1) goto done; } if (prime_factor(P)) { // 一般のケース for (i = 0; i < sz; i++) { k = id[factor[i]]; int s = sum(k, R); if (L > 1) s -= sum(k, L-1); if (s < power[i]) { ans = 0; break; } // 素因数の数の比較 } } else ans = 0; // Pに2000を超えた素因数が含まれたケース done: outs(ans? "Yes": "NO"); } return 0; }