結果

問題 No.1261 数字集め
ユーザー SSRSSSRS
提出日時 2020-10-16 23:29:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,540 ms / 8,000 ms
コード長 2,167 bytes
コンパイル時間 3,276 ms
コンパイル使用メモリ 174,732 KB
実行使用メモリ 115,868 KB
最終ジャッジ日時 2023-09-28 10:04:46
合計ジャッジ時間 112,409 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,540 ms
115,484 KB
testcase_01 AC 471 ms
40,312 KB
testcase_02 AC 1,054 ms
83,264 KB
testcase_03 AC 1,106 ms
84,028 KB
testcase_04 AC 656 ms
54,136 KB
testcase_05 AC 1,459 ms
110,556 KB
testcase_06 AC 762 ms
61,480 KB
testcase_07 AC 1,103 ms
86,888 KB
testcase_08 AC 602 ms
48,744 KB
testcase_09 AC 798 ms
63,856 KB
testcase_10 AC 17 ms
5,408 KB
testcase_11 AC 1,410 ms
108,956 KB
testcase_12 AC 1,278 ms
97,644 KB
testcase_13 AC 1,117 ms
88,072 KB
testcase_14 AC 65 ms
11,472 KB
testcase_15 AC 519 ms
43,524 KB
testcase_16 AC 1,104 ms
87,332 KB
testcase_17 AC 878 ms
70,336 KB
testcase_18 AC 526 ms
44,236 KB
testcase_19 AC 1,068 ms
84,536 KB
testcase_20 AC 86 ms
13,580 KB
testcase_21 AC 1,552 ms
115,492 KB
testcase_22 AC 1,558 ms
115,504 KB
testcase_23 AC 1,543 ms
115,392 KB
testcase_24 AC 1,559 ms
115,532 KB
testcase_25 AC 1,582 ms
115,568 KB
testcase_26 AC 1,518 ms
115,484 KB
testcase_27 AC 1,521 ms
115,504 KB
testcase_28 AC 1,530 ms
115,388 KB
testcase_29 AC 1,577 ms
115,500 KB
testcase_30 AC 1,582 ms
115,572 KB
testcase_31 AC 1,566 ms
115,596 KB
testcase_32 AC 1,568 ms
115,592 KB
testcase_33 AC 1,580 ms
115,532 KB
testcase_34 AC 1,519 ms
115,416 KB
testcase_35 AC 1,603 ms
115,504 KB
testcase_36 AC 1,531 ms
115,640 KB
testcase_37 AC 1,533 ms
115,608 KB
testcase_38 AC 1,580 ms
115,520 KB
testcase_39 AC 1,532 ms
115,520 KB
testcase_40 AC 1,534 ms
115,440 KB
testcase_41 AC 1,571 ms
115,532 KB
testcase_42 AC 1,597 ms
115,508 KB
testcase_43 AC 1,544 ms
115,508 KB
testcase_44 AC 1,412 ms
101,940 KB
testcase_45 AC 299 ms
24,260 KB
testcase_46 AC 736 ms
55,720 KB
testcase_47 AC 506 ms
39,252 KB
testcase_48 AC 1,117 ms
85,344 KB
testcase_49 AC 1,316 ms
100,892 KB
testcase_50 AC 1,245 ms
90,100 KB
testcase_51 AC 293 ms
26,972 KB
testcase_52 AC 33 ms
4,576 KB
testcase_53 AC 327 ms
26,904 KB
testcase_54 AC 437 ms
30,404 KB
testcase_55 AC 137 ms
15,624 KB
testcase_56 AC 210 ms
19,540 KB
testcase_57 AC 1,051 ms
81,164 KB
testcase_58 AC 263 ms
24,604 KB
testcase_59 AC 1,434 ms
103,524 KB
testcase_60 AC 348 ms
29,552 KB
testcase_61 AC 488 ms
40,764 KB
testcase_62 AC 1,255 ms
92,944 KB
testcase_63 AC 139 ms
17,580 KB
testcase_64 AC 1,560 ms
111,544 KB
testcase_65 AC 941 ms
73,828 KB
testcase_66 AC 833 ms
62,164 KB
testcase_67 AC 1,225 ms
93,868 KB
testcase_68 AC 724 ms
58,660 KB
testcase_69 AC 708 ms
57,372 KB
testcase_70 AC 584 ms
45,528 KB
testcase_71 AC 1,226 ms
88,808 KB
testcase_72 AC 390 ms
33,304 KB
testcase_73 AC 480 ms
38,188 KB
testcase_74 AC 171 ms
19,584 KB
testcase_75 AC 742 ms
53,760 KB
testcase_76 AC 1,128 ms
81,212 KB
testcase_77 AC 1,324 ms
94,528 KB
testcase_78 AC 32 ms
4,376 KB
testcase_79 AC 1,318 ms
98,244 KB
testcase_80 AC 60 ms
4,624 KB
testcase_81 AC 98 ms
12,332 KB
testcase_82 AC 1,045 ms
76,660 KB
testcase_83 AC 484 ms
35,056 KB
testcase_84 AC 1,639 ms
115,644 KB
testcase_85 AC 1,623 ms
115,728 KB
testcase_86 AC 1,634 ms
115,696 KB
testcase_87 AC 1,633 ms
115,580 KB
testcase_88 AC 1,646 ms
115,868 KB
testcase_89 AC 1,620 ms
115,652 KB
testcase_90 AC 1,683 ms
115,600 KB
testcase_91 AC 1,664 ms
115,752 KB
testcase_92 AC 1,693 ms
115,852 KB
testcase_93 AC 2,131 ms
115,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
  }
}
0