結果

問題 No.1261 数字集め
ユーザー SSRSSSRS
提出日時 2020-10-16 23:20:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,116 bytes
コンパイル時間 4,972 ms
コンパイル使用メモリ 173,344 KB
実行使用メモリ 70,560 KB
最終ジャッジ日時 2023-09-28 09:48:31
合計ジャッジ時間 32,330 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 97 ms
12,728 KB
testcase_02 AC 214 ms
22,548 KB
testcase_03 AC 222 ms
30,180 KB
testcase_04 AC 136 ms
18,012 KB
testcase_05 AC 296 ms
45,784 KB
testcase_06 AC 155 ms
21,148 KB
testcase_07 AC 234 ms
36,220 KB
testcase_08 AC 150 ms
25,596 KB
testcase_09 AC 208 ms
33,260 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 279 ms
29,196 KB
testcase_12 AC 235 ms
26,848 KB
testcase_13 AC 249 ms
29,216 KB
testcase_14 AC 30 ms
6,704 KB
testcase_15 AC 120 ms
18,644 KB
testcase_16 AC 233 ms
35,504 KB
testcase_17 AC 259 ms
37,212 KB
testcase_18 AC 129 ms
17,548 KB
testcase_19 AC 201 ms
25,220 KB
testcase_20 AC 38 ms
7,748 KB
testcase_21 AC 296 ms
30,280 KB
testcase_22 AC 292 ms
30,340 KB
testcase_23 AC 300 ms
30,288 KB
testcase_24 AC 358 ms
53,428 KB
testcase_25 AC 355 ms
53,476 KB
testcase_26 AC 357 ms
53,468 KB
testcase_27 AC 358 ms
53,572 KB
testcase_28 AC 355 ms
53,532 KB
testcase_29 AC 359 ms
53,572 KB
testcase_30 AC 357 ms
53,500 KB
testcase_31 AC 362 ms
53,500 KB
testcase_32 AC 359 ms
53,472 KB
testcase_33 AC 359 ms
53,404 KB
testcase_34 AC 356 ms
53,428 KB
testcase_35 AC 354 ms
53,512 KB
testcase_36 AC 384 ms
53,436 KB
testcase_37 AC 365 ms
53,504 KB
testcase_38 AC 367 ms
53,744 KB
testcase_39 AC 363 ms
53,508 KB
testcase_40 AC 364 ms
53,516 KB
testcase_41 AC 358 ms
53,452 KB
testcase_42 AC 357 ms
53,508 KB
testcase_43 AC 361 ms
53,568 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
権限があれば一括ダウンロードができます

ソースコード

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++){
    if (N % a == 0){
      for (int b = a * 2; b < N; b += a){
        prev[b].push_back(a);
        if (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