結果
問題 | No.1261 数字集め |
ユーザー | magsta |
提出日時 | 2020-10-14 22:49:08 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,520 ms / 8,000 ms |
コード長 | 3,937 bytes |
コンパイル時間 | 1,294 ms |
コンパイル使用メモリ | 91,860 KB |
実行使用メモリ | 145,920 KB |
最終ジャッジ日時 | 2024-07-21 04:50:07 |
合計ジャッジ時間 | 118,135 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,520 ms
145,448 KB |
testcase_01 | AC | 489 ms
83,200 KB |
testcase_02 | AC | 1,188 ms
118,784 KB |
testcase_03 | AC | 1,152 ms
119,472 KB |
testcase_04 | AC | 693 ms
94,944 KB |
testcase_05 | AC | 1,595 ms
141,056 KB |
testcase_06 | AC | 811 ms
100,864 KB |
testcase_07 | AC | 1,204 ms
121,848 KB |
testcase_08 | AC | 646 ms
90,496 KB |
testcase_09 | AC | 836 ms
102,912 KB |
testcase_10 | AC | 60 ms
52,736 KB |
testcase_11 | AC | 1,698 ms
140,032 KB |
testcase_12 | AC | 1,380 ms
130,620 KB |
testcase_13 | AC | 1,228 ms
122,864 KB |
testcase_14 | AC | 110 ms
58,256 KB |
testcase_15 | AC | 548 ms
86,016 KB |
testcase_16 | AC | 1,214 ms
121,984 KB |
testcase_17 | AC | 947 ms
108,288 KB |
testcase_18 | AC | 585 ms
86,784 KB |
testcase_19 | AC | 1,177 ms
119,936 KB |
testcase_20 | AC | 143 ms
60,160 KB |
testcase_21 | AC | 1,754 ms
144,896 KB |
testcase_22 | AC | 1,691 ms
145,008 KB |
testcase_23 | AC | 1,663 ms
145,152 KB |
testcase_24 | AC | 1,677 ms
145,052 KB |
testcase_25 | AC | 1,687 ms
145,152 KB |
testcase_26 | AC | 1,673 ms
145,016 KB |
testcase_27 | AC | 1,632 ms
144,972 KB |
testcase_28 | AC | 1,723 ms
145,024 KB |
testcase_29 | AC | 1,653 ms
145,024 KB |
testcase_30 | AC | 1,672 ms
145,152 KB |
testcase_31 | AC | 1,673 ms
145,024 KB |
testcase_32 | AC | 1,679 ms
145,024 KB |
testcase_33 | AC | 1,654 ms
145,020 KB |
testcase_34 | AC | 1,693 ms
145,024 KB |
testcase_35 | AC | 1,679 ms
144,896 KB |
testcase_36 | AC | 1,645 ms
145,152 KB |
testcase_37 | AC | 1,698 ms
145,024 KB |
testcase_38 | AC | 1,680 ms
145,024 KB |
testcase_39 | AC | 1,665 ms
145,056 KB |
testcase_40 | AC | 1,709 ms
145,024 KB |
testcase_41 | AC | 1,710 ms
145,024 KB |
testcase_42 | AC | 1,703 ms
145,008 KB |
testcase_43 | AC | 1,691 ms
145,008 KB |
testcase_44 | AC | 1,517 ms
134,340 KB |
testcase_45 | AC | 331 ms
70,016 KB |
testcase_46 | AC | 726 ms
96,328 KB |
testcase_47 | AC | 534 ms
82,828 KB |
testcase_48 | AC | 1,219 ms
120,832 KB |
testcase_49 | AC | 1,478 ms
133,376 KB |
testcase_50 | AC | 1,650 ms
125,056 KB |
testcase_51 | AC | 325 ms
72,064 KB |
testcase_52 | AC | 70 ms
52,228 KB |
testcase_53 | AC | 362 ms
72,576 KB |
testcase_54 | AC | 451 ms
75,648 KB |
testcase_55 | AC | 198 ms
62,548 KB |
testcase_56 | AC | 282 ms
65,920 KB |
testcase_57 | AC | 1,188 ms
117,376 KB |
testcase_58 | AC | 317 ms
70,272 KB |
testcase_59 | AC | 1,559 ms
135,936 KB |
testcase_60 | AC | 392 ms
74,624 KB |
testcase_61 | AC | 545 ms
84,096 KB |
testcase_62 | AC | 1,416 ms
127,360 KB |
testcase_63 | AC | 200 ms
63,920 KB |
testcase_64 | AC | 1,714 ms
142,464 KB |
testcase_65 | AC | 1,038 ms
111,488 KB |
testcase_66 | AC | 830 ms
101,504 KB |
testcase_67 | AC | 1,334 ms
127,488 KB |
testcase_68 | AC | 803 ms
98,816 KB |
testcase_69 | AC | 735 ms
97,536 KB |
testcase_70 | AC | 651 ms
88,448 KB |
testcase_71 | AC | 1,314 ms
123,776 KB |
testcase_72 | AC | 444 ms
77,720 KB |
testcase_73 | AC | 510 ms
81,920 KB |
testcase_74 | AC | 240 ms
65,664 KB |
testcase_75 | AC | 764 ms
95,360 KB |
testcase_76 | AC | 1,135 ms
117,376 KB |
testcase_77 | AC | 1,345 ms
128,272 KB |
testcase_78 | AC | 66 ms
51,052 KB |
testcase_79 | AC | 1,424 ms
131,072 KB |
testcase_80 | AC | 102 ms
52,608 KB |
testcase_81 | AC | 169 ms
59,264 KB |
testcase_82 | AC | 1,109 ms
113,920 KB |
testcase_83 | AC | 502 ms
79,488 KB |
testcase_84 | AC | 1,787 ms
145,920 KB |
testcase_85 | AC | 1,781 ms
145,920 KB |
testcase_86 | AC | 1,813 ms
145,792 KB |
testcase_87 | AC | 1,799 ms
145,792 KB |
testcase_88 | AC | 1,797 ms
145,832 KB |
testcase_89 | AC | 1,781 ms
145,792 KB |
testcase_90 | AC | 1,855 ms
145,792 KB |
testcase_91 | AC | 1,780 ms
145,816 KB |
testcase_92 | AC | 1,774 ms
145,848 KB |
testcase_93 | AC | 1,792 ms
145,816 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <utility> #include <map> #define MOD 1000000007 using namespace std; long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } long long modinv(long long a) { return modpow(a, MOD - 2); } vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); // 重複しないならば i の相方である N/i も push if (N/i != i) res.push_back(N/i); } } // 小さい順に並び替える sort(res.begin(), res.end()); return res; } long long p_q_r(long long p, long long q, long long r, long long M){ if (r > p) swap(p, r); if (q > p) swap(p, q); if (r > q) swap(q, r); long long a, b, c, d, e; a = modpow(p, M - 2); b = modpow(q, M - 2); c = modpow(r, M - 2); d = (((a - c) * modinv(p - r) % MOD) + MOD) % MOD; e = (((b - c) * modinv(q - r) % MOD) + MOD) % MOD; d = d * p % MOD; e = e * q % MOD; return (((d - e) * modinv(p - q) % MOD) + MOD) % MOD; } int main() { long long N, M; cin >> N >> M; long long A[N]; for (int i = 1; i < N; i++) cin >> A[i]; map<long long, long long> Map; for (int i = 1; i < N; i++){ Map[A[i]]++; if (Map[A[i]] > 1) cout << "errar" << endl; if (A[i] < 2 || A[i] > 1000000) cout << "errbr" << endl; } const auto &res = enum_divisors(N); long long count = 0; long long ans = 0; for (int i = 0; i < res.size(); i++){ for (int j = 0; j < res.size(); j++){ if (res[i] == 1 || res[j] == 1) continue; if (N == (res[i] * res[j])) continue; if (N % (res[i] * res[j]) == 0){ long long p = A[res[i] - 1] - 1; long long q = A[res[i] * res[j] - 1] - 1; long long r = A[N - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } } } cout << ans << endl; long long Q; cin >> Q; if (Q < 0 || Q > 10000) cout << "errer" << endl; vector<long long> num[N]; bool flag[N]; for (int i = 0; i < N; i++) flag[i] = false; map<long long, long long> Map_[1000001]; for (int i = 0; i < Q; i++){ long long X, Y; cin >> X >> Y; if (X >= Y || X < 1 || Y > N) cout << "errfr" << endl; if (Y % X == 0) cout << "errgr" << endl; Map_[X][Y]++; if (Map_[X][Y] > 1) cout << "errxr" << endl; if (Y == N){ const auto &res_ = enum_divisors(X); for (int i = 0; i < res_.size(); i++){ if (res_[i] == 1 || res_[i] == X) continue; long long p = A[res_[i] - 1] - 1; long long q = A[X - 1] - 1; long long r = A[Y - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } for (int i = 0; i < num[X - 1].size(); i++){ long long p = A[num[X - 1][i] - 1] - 1; long long q = A[X - 1] - 1; long long r = A[Y - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } flag[X - 1] = true; } if (Y != N){ if (N % Y == 0){ long long p = A[X - 1] - 1; long long q = A[Y - 1] - 1; long long r = A[N - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } if (flag[Y - 1] == true){ long long p = A[X - 1] - 1; long long q = A[Y - 1] - 1; long long r = A[N - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } num[Y - 1].push_back(X); } cout << ans << endl; } }