結果
問題 | No.1261 数字集め |
ユーザー | SSRS |
提出日時 | 2020-10-16 23:29:13 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3,116 ms / 8,000 ms |
コード長 | 2,167 bytes |
コンパイル時間 | 2,203 ms |
コンパイル使用メモリ | 177,172 KB |
実行使用メモリ | 115,968 KB |
最終ジャッジ日時 | 2024-07-21 04:41:39 |
合計ジャッジ時間 | 148,522 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3,116 ms
115,584 KB |
testcase_01 | AC | 596 ms
40,576 KB |
testcase_02 | AC | 1,471 ms
83,200 KB |
testcase_03 | AC | 1,483 ms
84,224 KB |
testcase_04 | AC | 884 ms
54,400 KB |
testcase_05 | AC | 2,057 ms
110,848 KB |
testcase_06 | AC | 995 ms
61,696 KB |
testcase_07 | AC | 1,503 ms
87,040 KB |
testcase_08 | AC | 758 ms
49,152 KB |
testcase_09 | AC | 1,010 ms
63,872 KB |
testcase_10 | AC | 19 ms
5,632 KB |
testcase_11 | AC | 2,044 ms
109,312 KB |
testcase_12 | AC | 1,755 ms
97,792 KB |
testcase_13 | AC | 1,517 ms
88,448 KB |
testcase_14 | AC | 65 ms
11,776 KB |
testcase_15 | AC | 633 ms
43,648 KB |
testcase_16 | AC | 1,597 ms
87,424 KB |
testcase_17 | AC | 1,181 ms
70,656 KB |
testcase_18 | AC | 670 ms
44,544 KB |
testcase_19 | AC | 1,561 ms
84,608 KB |
testcase_20 | AC | 96 ms
13,696 KB |
testcase_21 | AC | 2,182 ms
115,712 KB |
testcase_22 | AC | 2,140 ms
115,712 KB |
testcase_23 | AC | 2,093 ms
115,784 KB |
testcase_24 | AC | 2,098 ms
115,888 KB |
testcase_25 | AC | 2,227 ms
115,840 KB |
testcase_26 | AC | 2,175 ms
115,712 KB |
testcase_27 | AC | 2,180 ms
115,712 KB |
testcase_28 | AC | 2,190 ms
115,712 KB |
testcase_29 | AC | 2,140 ms
115,712 KB |
testcase_30 | AC | 2,108 ms
115,840 KB |
testcase_31 | AC | 2,135 ms
115,712 KB |
testcase_32 | AC | 2,225 ms
115,712 KB |
testcase_33 | AC | 2,182 ms
115,712 KB |
testcase_34 | AC | 2,161 ms
115,712 KB |
testcase_35 | AC | 2,163 ms
115,712 KB |
testcase_36 | AC | 2,148 ms
115,712 KB |
testcase_37 | AC | 2,128 ms
115,712 KB |
testcase_38 | AC | 2,167 ms
115,840 KB |
testcase_39 | AC | 2,215 ms
115,840 KB |
testcase_40 | AC | 2,189 ms
115,712 KB |
testcase_41 | AC | 2,168 ms
115,712 KB |
testcase_42 | AC | 2,183 ms
115,712 KB |
testcase_43 | AC | 2,115 ms
115,712 KB |
testcase_44 | AC | 1,852 ms
102,016 KB |
testcase_45 | AC | 298 ms
24,320 KB |
testcase_46 | AC | 871 ms
56,064 KB |
testcase_47 | AC | 598 ms
39,424 KB |
testcase_48 | AC | 1,524 ms
85,632 KB |
testcase_49 | AC | 1,839 ms
100,992 KB |
testcase_50 | AC | 1,681 ms
90,192 KB |
testcase_51 | AC | 358 ms
27,008 KB |
testcase_52 | AC | 35 ms
5,376 KB |
testcase_53 | AC | 381 ms
27,264 KB |
testcase_54 | AC | 494 ms
30,592 KB |
testcase_55 | AC | 147 ms
15,872 KB |
testcase_56 | AC | 243 ms
19,584 KB |
testcase_57 | AC | 1,432 ms
81,280 KB |
testcase_58 | AC | 315 ms
24,832 KB |
testcase_59 | AC | 1,910 ms
103,808 KB |
testcase_60 | AC | 403 ms
29,740 KB |
testcase_61 | AC | 602 ms
41,088 KB |
testcase_62 | AC | 1,730 ms
93,056 KB |
testcase_63 | AC | 143 ms
17,920 KB |
testcase_64 | AC | 2,148 ms
111,744 KB |
testcase_65 | AC | 1,304 ms
73,984 KB |
testcase_66 | AC | 1,060 ms
62,080 KB |
testcase_67 | AC | 1,800 ms
93,952 KB |
testcase_68 | AC | 1,060 ms
58,880 KB |
testcase_69 | AC | 933 ms
57,472 KB |
testcase_70 | AC | 746 ms
45,824 KB |
testcase_71 | AC | 1,646 ms
88,960 KB |
testcase_72 | AC | 457 ms
33,432 KB |
testcase_73 | AC | 570 ms
38,656 KB |
testcase_74 | AC | 189 ms
19,840 KB |
testcase_75 | AC | 898 ms
54,016 KB |
testcase_76 | AC | 1,420 ms
81,408 KB |
testcase_77 | AC | 1,739 ms
94,720 KB |
testcase_78 | AC | 32 ms
5,376 KB |
testcase_79 | AC | 1,816 ms
98,304 KB |
testcase_80 | AC | 62 ms
5,376 KB |
testcase_81 | AC | 106 ms
12,416 KB |
testcase_82 | AC | 1,416 ms
76,800 KB |
testcase_83 | AC | 552 ms
35,200 KB |
testcase_84 | AC | 2,244 ms
115,968 KB |
testcase_85 | AC | 2,245 ms
115,968 KB |
testcase_86 | AC | 2,255 ms
115,968 KB |
testcase_87 | AC | 2,259 ms
115,840 KB |
testcase_88 | AC | 2,282 ms
115,840 KB |
testcase_89 | AC | 2,278 ms
115,840 KB |
testcase_90 | AC | 2,293 ms
115,968 KB |
testcase_91 | AC | 2,286 ms
115,968 KB |
testcase_92 | AC | 2,230 ms
115,840 KB |
testcase_93 | AC | 2,207 ms
115,840 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; array<array<long long, 3>, 3> matmul(array<array<long long, 3>, 3> &A, array<array<long long, 3>, 3> &B){ array<array<long long, 3>, 3> ans; for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ ans[i][j] = 0; } } for (int i = 0; i < 3; i++){ for (int k = 0; k < 3; k++){ for (int j = 0; j < 3; j++){ ans[i][k] += A[i][j] * B[j][k]; } ans[i][k] %= MOD; } } return ans; } array<array<long long, 3>, 3> matexp(array<array<long long, 3>, 3> &A, long long b){ array<array<long long, 3>, 3> ans; for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ ans[i][j] = i == j; } } while (b > 0){ if (b % 2 == 1){ ans = matmul(ans, A); } A = matmul(A, A); b /= 2; } return ans; } long long get(vector<int> &A, int M, int a, int b){ array<array<long long, 3>, 3> mat; mat[0][0] = A[a - 1] - 1; mat[0][1] = 1; mat[0][2] = 0; mat[1][0] = 0; mat[1][1] = A[b - 1] - 1; mat[1][2] = 1; mat[2][0] = 0; mat[2][1] = 0; mat[2][2] = A.back() - 1; mat = matexp(mat, M - 1); return mat[0][2]; } int main(){ int N, M; cin >> N >> M; vector<int> A(N, 0); for (int i = 1; i < N; i++){ cin >> A[i]; } long long ans = 0; vector<vector<int>> prev(N + 1); for (int a = 2; a < N; a++){ for (int b = a * 2; b < N; b += a){ prev[b].push_back(a); if (N % a == 0 && N % b == 0){ ans += get(A, M, a, b); if (ans >= MOD){ ans -= MOD; } } } } cout << ans << endl; int Q; cin >> Q; set<int> st; for (int i = 2; i < N; i++){ if (N % i == 0){ st.insert(i); } } for (int i = 0; i < Q; i++){ int X, Y; cin >> X >> Y; if (Y == N){ for (int a : prev[X]){ ans += get(A, M, a, X); if (ans >= MOD){ ans -= MOD; } } st.insert(X); } else { if (st.count(Y)){ ans += get(A, M, X, Y); if (ans >= MOD){ ans -= MOD; } } } prev[Y].push_back(X); cout << ans << endl; } }