結果
問題 | No.1261 数字集め |
ユーザー | magsta |
提出日時 | 2020-10-14 22:37:18 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,946 ms / 8,000 ms |
コード長 | 3,587 bytes |
コンパイル時間 | 1,377 ms |
コンパイル使用メモリ | 90,492 KB |
実行使用メモリ | 98,364 KB |
最終ジャッジ日時 | 2024-07-21 04:43:57 |
合計ジャッジ時間 | 91,778 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,946 ms
98,048 KB |
testcase_01 | AC | 340 ms
36,224 KB |
testcase_02 | AC | 843 ms
71,680 KB |
testcase_03 | AC | 883 ms
72,576 KB |
testcase_04 | AC | 512 ms
48,160 KB |
testcase_05 | AC | 1,227 ms
94,080 KB |
testcase_06 | AC | 578 ms
54,120 KB |
testcase_07 | AC | 982 ms
75,008 KB |
testcase_08 | AC | 452 ms
43,584 KB |
testcase_09 | AC | 677 ms
55,936 KB |
testcase_10 | AC | 21 ms
5,888 KB |
testcase_11 | AC | 1,491 ms
92,928 KB |
testcase_12 | AC | 1,053 ms
83,756 KB |
testcase_13 | AC | 929 ms
75,992 KB |
testcase_14 | AC | 63 ms
11,392 KB |
testcase_15 | AC | 481 ms
39,040 KB |
testcase_16 | AC | 1,008 ms
75,136 KB |
testcase_17 | AC | 693 ms
61,312 KB |
testcase_18 | AC | 369 ms
39,808 KB |
testcase_19 | AC | 863 ms
72,960 KB |
testcase_20 | AC | 110 ms
13,312 KB |
testcase_21 | AC | 1,286 ms
98,176 KB |
testcase_22 | AC | 1,319 ms
98,080 KB |
testcase_23 | AC | 1,282 ms
98,048 KB |
testcase_24 | AC | 1,277 ms
98,148 KB |
testcase_25 | AC | 1,432 ms
98,032 KB |
testcase_26 | AC | 1,426 ms
98,176 KB |
testcase_27 | AC | 1,387 ms
98,140 KB |
testcase_28 | AC | 1,285 ms
98,048 KB |
testcase_29 | AC | 1,273 ms
98,176 KB |
testcase_30 | AC | 1,246 ms
98,172 KB |
testcase_31 | AC | 1,220 ms
98,176 KB |
testcase_32 | AC | 1,197 ms
98,176 KB |
testcase_33 | AC | 1,340 ms
98,140 KB |
testcase_34 | AC | 1,336 ms
98,188 KB |
testcase_35 | AC | 1,393 ms
98,048 KB |
testcase_36 | AC | 1,248 ms
98,300 KB |
testcase_37 | AC | 1,288 ms
98,048 KB |
testcase_38 | AC | 1,267 ms
98,164 KB |
testcase_39 | AC | 1,318 ms
98,304 KB |
testcase_40 | AC | 1,471 ms
98,044 KB |
testcase_41 | AC | 1,389 ms
98,104 KB |
testcase_42 | AC | 1,310 ms
98,248 KB |
testcase_43 | AC | 1,375 ms
98,176 KB |
testcase_44 | AC | 1,245 ms
87,168 KB |
testcase_45 | AC | 225 ms
22,656 KB |
testcase_46 | AC | 518 ms
49,408 KB |
testcase_47 | AC | 379 ms
35,500 KB |
testcase_48 | AC | 889 ms
73,816 KB |
testcase_49 | AC | 1,114 ms
86,272 KB |
testcase_50 | AC | 1,005 ms
77,608 KB |
testcase_51 | AC | 205 ms
24,912 KB |
testcase_52 | AC | 29 ms
5,376 KB |
testcase_53 | AC | 316 ms
25,080 KB |
testcase_54 | AC | 342 ms
28,032 KB |
testcase_55 | AC | 137 ms
15,104 KB |
testcase_56 | AC | 229 ms
18,448 KB |
testcase_57 | AC | 988 ms
70,188 KB |
testcase_58 | AC | 284 ms
23,100 KB |
testcase_59 | AC | 1,239 ms
88,576 KB |
testcase_60 | AC | 353 ms
27,392 KB |
testcase_61 | AC | 375 ms
36,740 KB |
testcase_62 | AC | 1,012 ms
79,744 KB |
testcase_63 | AC | 142 ms
17,128 KB |
testcase_64 | AC | 1,300 ms
95,104 KB |
testcase_65 | AC | 717 ms
64,256 KB |
testcase_66 | AC | 594 ms
54,656 KB |
testcase_67 | AC | 980 ms
80,512 KB |
testcase_68 | AC | 552 ms
51,776 KB |
testcase_69 | AC | 516 ms
50,804 KB |
testcase_70 | AC | 454 ms
40,832 KB |
testcase_71 | AC | 969 ms
76,464 KB |
testcase_72 | AC | 318 ms
30,464 KB |
testcase_73 | AC | 352 ms
34,688 KB |
testcase_74 | AC | 151 ms
18,688 KB |
testcase_75 | AC | 559 ms
47,868 KB |
testcase_76 | AC | 851 ms
70,400 KB |
testcase_77 | AC | 1,041 ms
81,172 KB |
testcase_78 | AC | 26 ms
5,376 KB |
testcase_79 | AC | 1,106 ms
84,136 KB |
testcase_80 | AC | 60 ms
5,376 KB |
testcase_81 | AC | 119 ms
12,160 KB |
testcase_82 | AC | 884 ms
66,688 KB |
testcase_83 | AC | 349 ms
32,000 KB |
testcase_84 | AC | 1,357 ms
98,304 KB |
testcase_85 | AC | 1,407 ms
98,304 KB |
testcase_86 | AC | 1,345 ms
98,304 KB |
testcase_87 | AC | 1,314 ms
98,304 KB |
testcase_88 | AC | 1,409 ms
98,304 KB |
testcase_89 | AC | 1,328 ms
98,364 KB |
testcase_90 | AC | 1,329 ms
98,176 KB |
testcase_91 | AC | 1,419 ms
98,304 KB |
testcase_92 | AC | 1,351 ms
98,304 KB |
testcase_93 | AC | 1,361 ms
98,304 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 = 0; i < N; i++){ Map[A[i]]++; if (Map[A[i]] > 1) cout << "error" << 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; vector<long long> num[N]; bool flag[N]; for (int i = 0; i < N; i++) flag[i] = false; for (int i = 0; i < Q; i++){ long long X, Y; cin >> X >> Y; 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; } }