結果
問題 | No.854 公平なりんご分配 |
ユーザー |
![]() |
提出日時 | 2019-07-27 11:57:37 |
言語 | C (gcc 13.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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 92 |
コンパイルメッセージ
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)#endifint 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 305int 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 という条件を満たす最小のiint 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 という条件を満たす最小のiint 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;}