結果

問題 No.1261 数字集め
ユーザー SSRSSSRS
提出日時 2020-10-16 23:22:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,085 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 176,504 KB
実行使用メモリ 115,852 KB
最終ジャッジ日時 2023-09-28 10:02:21
合計ジャッジ時間 111,404 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,563 ms
115,532 KB
testcase_01 AC 478 ms
40,000 KB
testcase_02 AC 1,073 ms
82,908 KB
testcase_03 AC 1,132 ms
84,280 KB
testcase_04 AC 658 ms
54,144 KB
testcase_05 AC 1,506 ms
110,652 KB
testcase_06 AC 823 ms
61,608 KB
testcase_07 AC 1,160 ms
86,868 KB
testcase_08 AC 600 ms
48,812 KB
testcase_09 AC 830 ms
63,572 KB
testcase_10 AC 18 ms
5,408 KB
testcase_11 AC 1,460 ms
108,996 KB
testcase_12 AC 1,273 ms
97,724 KB
testcase_13 AC 1,125 ms
88,248 KB
testcase_14 AC 63 ms
11,536 KB
testcase_15 AC 517 ms
43,396 KB
testcase_16 AC 1,099 ms
87,228 KB
testcase_17 AC 897 ms
70,324 KB
testcase_18 AC 494 ms
44,152 KB
testcase_19 AC 1,107 ms
84,340 KB
testcase_20 AC 91 ms
13,540 KB
testcase_21 AC 1,582 ms
115,516 KB
testcase_22 AC 1,513 ms
115,440 KB
testcase_23 AC 1,569 ms
115,664 KB
testcase_24 AC 1,505 ms
115,536 KB
testcase_25 AC 1,551 ms
115,540 KB
testcase_26 AC 1,572 ms
115,588 KB
testcase_27 AC 1,549 ms
115,760 KB
testcase_28 AC 1,564 ms
115,752 KB
testcase_29 AC 1,562 ms
115,416 KB
testcase_30 AC 1,571 ms
115,532 KB
testcase_31 AC 1,586 ms
115,596 KB
testcase_32 AC 1,595 ms
115,764 KB
testcase_33 AC 1,584 ms
115,608 KB
testcase_34 AC 1,574 ms
115,460 KB
testcase_35 AC 1,527 ms
115,412 KB
testcase_36 AC 1,539 ms
115,520 KB
testcase_37 AC 1,586 ms
115,528 KB
testcase_38 AC 1,561 ms
115,592 KB
testcase_39 AC 1,543 ms
115,444 KB
testcase_40 AC 1,577 ms
115,764 KB
testcase_41 AC 1,591 ms
115,460 KB
testcase_42 AC 1,598 ms
115,604 KB
testcase_43 AC 1,578 ms
115,484 KB
testcase_44 AC 1,387 ms
101,940 KB
testcase_45 AC 302 ms
24,212 KB
testcase_46 AC 669 ms
55,884 KB
testcase_47 AC 496 ms
39,232 KB
testcase_48 AC 1,150 ms
85,332 KB
testcase_49 AC 1,331 ms
101,024 KB
testcase_50 AC 1,226 ms
90,188 KB
testcase_51 AC 301 ms
26,912 KB
testcase_52 AC 34 ms
4,616 KB
testcase_53 AC 311 ms
27,172 KB
testcase_54 AC 405 ms
30,340 KB
testcase_55 AC 150 ms
15,624 KB
testcase_56 AC 214 ms
19,292 KB
testcase_57 AC 1,117 ms
81,388 KB
testcase_58 AC 308 ms
24,600 KB
testcase_59 AC 1,405 ms
103,364 KB
testcase_60 AC 352 ms
29,780 KB
testcase_61 AC 514 ms
40,824 KB
testcase_62 AC 1,301 ms
93,040 KB
testcase_63 AC 160 ms
17,608 KB
testcase_64 AC 1,578 ms
111,704 KB
testcase_65 AC 981 ms
73,776 KB
testcase_66 AC 795 ms
62,260 KB
testcase_67 AC 1,220 ms
93,980 KB
testcase_68 AC 770 ms
58,560 KB
testcase_69 AC 746 ms
57,392 KB
testcase_70 AC 584 ms
45,808 KB
testcase_71 AC 1,194 ms
88,812 KB
testcase_72 AC 414 ms
33,180 KB
testcase_73 AC 478 ms
38,260 KB
testcase_74 AC 190 ms
19,588 KB
testcase_75 AC 720 ms
53,656 KB
testcase_76 AC 1,077 ms
81,168 KB
testcase_77 AC 1,281 ms
94,608 KB
testcase_78 AC 31 ms
4,376 KB
testcase_79 AC 1,316 ms
98,380 KB
testcase_80 WA -
testcase_81 AC 106 ms
12,196 KB
testcase_82 AC 1,062 ms
76,796 KB
testcase_83 AC 500 ms
35,256 KB
testcase_84 AC 1,650 ms
115,852 KB
testcase_85 AC 1,640 ms
115,440 KB
testcase_86 AC 1,596 ms
115,672 KB
testcase_87 AC 1,676 ms
115,548 KB
testcase_88 AC 1,698 ms
115,592 KB
testcase_89 AC 1,677 ms
115,704 KB
testcase_90 AC 1,618 ms
115,756 KB
testcase_91 AC 1,667 ms
115,748 KB
testcase_92 AC 1,614 ms
115,592 KB
testcase_93 AC 1,639 ms
115,796 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 = 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