結果
問題 | No.854 公平なりんご分配 |
ユーザー | bal4u |
提出日時 | 2019-07-27 11:57:37 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 86 ms / 3,153 ms |
コード長 | 4,176 bytes |
コンパイル時間 | 342 ms |
コンパイル使用メモリ | 34,560 KB |
実行使用メモリ | 120,448 KB |
最終ジャッジ日時 | 2024-07-02 10:53:06 |
合計ジャッジ時間 | 5,400 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 3 ms
11,908 KB |
testcase_13 | AC | 2 ms
9,864 KB |
testcase_14 | AC | 1 ms
6,944 KB |
testcase_15 | AC | 2 ms
9,852 KB |
testcase_16 | AC | 3 ms
11,900 KB |
testcase_17 | AC | 2 ms
11,900 KB |
testcase_18 | AC | 2 ms
11,896 KB |
testcase_19 | AC | 2 ms
11,900 KB |
testcase_20 | AC | 2 ms
7,812 KB |
testcase_21 | AC | 2 ms
9,856 KB |
testcase_22 | AC | 20 ms
89,720 KB |
testcase_23 | AC | 21 ms
106,132 KB |
testcase_24 | AC | 24 ms
116,484 KB |
testcase_25 | AC | 21 ms
104,072 KB |
testcase_26 | AC | 22 ms
106,260 KB |
testcase_27 | AC | 21 ms
108,164 KB |
testcase_28 | AC | 15 ms
71,300 KB |
testcase_29 | AC | 16 ms
81,540 KB |
testcase_30 | AC | 20 ms
100,108 KB |
testcase_31 | AC | 23 ms
112,244 KB |
testcase_32 | AC | 30 ms
118,580 KB |
testcase_33 | AC | 30 ms
118,456 KB |
testcase_34 | AC | 36 ms
120,440 KB |
testcase_35 | AC | 32 ms
118,720 KB |
testcase_36 | AC | 28 ms
116,340 KB |
testcase_37 | AC | 29 ms
118,744 KB |
testcase_38 | AC | 28 ms
118,564 KB |
testcase_39 | AC | 42 ms
120,444 KB |
testcase_40 | AC | 31 ms
118,440 KB |
testcase_41 | AC | 31 ms
118,600 KB |
testcase_42 | AC | 34 ms
120,448 KB |
testcase_43 | AC | 36 ms
118,592 KB |
testcase_44 | AC | 37 ms
118,644 KB |
testcase_45 | AC | 35 ms
118,440 KB |
testcase_46 | AC | 39 ms
118,692 KB |
testcase_47 | AC | 30 ms
118,752 KB |
testcase_48 | AC | 34 ms
118,720 KB |
testcase_49 | AC | 33 ms
118,696 KB |
testcase_50 | AC | 28 ms
118,572 KB |
testcase_51 | AC | 40 ms
118,744 KB |
testcase_52 | AC | 33 ms
118,488 KB |
testcase_53 | AC | 29 ms
118,448 KB |
testcase_54 | AC | 35 ms
120,448 KB |
testcase_55 | AC | 27 ms
118,452 KB |
testcase_56 | AC | 27 ms
118,440 KB |
testcase_57 | AC | 29 ms
118,436 KB |
testcase_58 | AC | 33 ms
118,428 KB |
testcase_59 | AC | 26 ms
120,436 KB |
testcase_60 | AC | 30 ms
118,452 KB |
testcase_61 | AC | 26 ms
118,424 KB |
testcase_62 | AC | 32 ms
118,460 KB |
testcase_63 | AC | 29 ms
118,460 KB |
testcase_64 | AC | 26 ms
120,440 KB |
testcase_65 | AC | 31 ms
118,744 KB |
testcase_66 | AC | 29 ms
118,456 KB |
testcase_67 | AC | 32 ms
118,596 KB |
testcase_68 | AC | 31 ms
118,444 KB |
testcase_69 | AC | 31 ms
118,744 KB |
testcase_70 | AC | 26 ms
118,440 KB |
testcase_71 | AC | 27 ms
118,456 KB |
testcase_72 | AC | 31 ms
118,436 KB |
testcase_73 | AC | 29 ms
118,568 KB |
testcase_74 | AC | 34 ms
118,744 KB |
testcase_75 | AC | 28 ms
118,468 KB |
testcase_76 | AC | 31 ms
118,716 KB |
testcase_77 | AC | 33 ms
120,440 KB |
testcase_78 | AC | 34 ms
120,440 KB |
testcase_79 | AC | 33 ms
118,620 KB |
testcase_80 | AC | 33 ms
118,572 KB |
testcase_81 | AC | 30 ms
118,616 KB |
testcase_82 | AC | 54 ms
119,772 KB |
testcase_83 | AC | 55 ms
119,576 KB |
testcase_84 | AC | 52 ms
119,472 KB |
testcase_85 | AC | 21 ms
6,940 KB |
testcase_86 | AC | 6 ms
6,940 KB |
testcase_87 | AC | 58 ms
120,440 KB |
testcase_88 | AC | 59 ms
119,648 KB |
testcase_89 | AC | 58 ms
119,680 KB |
testcase_90 | AC | 58 ms
119,512 KB |
testcase_91 | AC | 57 ms
119,924 KB |
testcase_92 | AC | 84 ms
119,588 KB |
testcase_93 | AC | 86 ms
119,524 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 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; for (i = 1; n > 1 && i <= SIZE; i++) { if (n % ptbl[i]) continue; v = ptbl[i], 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; } int main() { int i, k, Q, ans; int P, L, R, _P, _L, _R, _a; for (i = 1; i < TBL; i++) id[ptbl[i]] = i; bitn = in(), zero[0] = 1; 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--) { P = in(), L = in(), R = in(); if (P == _P && L == _L && R == _R) { ans = _a; goto done; } _P = P, _L = L, _R = R; ans = 1; if (P == 1) goto done; if (zw) { i = lower_bound(L), k = upper_bound(i, R); if (k-1 >= i) goto done; } ans = 0; if (prime_factor(P)) { ans = 1; 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; } } } done: outs(ans? "Yes": "NO"); _a = ans; } return 0; }