結果

問題 No.1261 数字集め
ユーザー SSRSSSRS
提出日時 2020-10-16 23:16:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,267 bytes
コンパイル時間 3,282 ms
コンパイル使用メモリ 175,856 KB
実行使用メモリ 31,080 KB
最終ジャッジ日時 2023-09-28 09:46:43
合計ジャッジ時間 29,892 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 103 ms
12,796 KB
testcase_02 AC 212 ms
22,828 KB
testcase_03 AC 216 ms
23,072 KB
testcase_04 AC 140 ms
16,012 KB
testcase_05 AC 284 ms
29,312 KB
testcase_06 AC 158 ms
17,684 KB
testcase_07 AC 224 ms
23,640 KB
testcase_08 AC 128 ms
14,636 KB
testcase_09 AC 166 ms
18,248 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 276 ms
28,920 KB
testcase_12 AC 248 ms
26,268 KB
testcase_13 AC 225 ms
23,864 KB
testcase_14 AC 27 ms
5,388 KB
testcase_15 AC 113 ms
13,328 KB
testcase_16 AC 222 ms
23,660 KB
testcase_17 AC 184 ms
19,716 KB
testcase_18 AC 115 ms
13,744 KB
testcase_19 AC 216 ms
23,132 KB
testcase_20 AC 34 ms
5,920 KB
testcase_21 AC 292 ms
30,512 KB
testcase_22 AC 293 ms
30,324 KB
testcase_23 AC 292 ms
30,196 KB
testcase_24 AC 297 ms
30,336 KB
testcase_25 AC 297 ms
30,324 KB
testcase_26 AC 300 ms
30,516 KB
testcase_27 AC 303 ms
30,252 KB
testcase_28 AC 298 ms
30,356 KB
testcase_29 AC 297 ms
30,356 KB
testcase_30 AC 296 ms
30,260 KB
testcase_31 AC 303 ms
30,204 KB
testcase_32 AC 299 ms
30,336 KB
testcase_33 AC 297 ms
30,272 KB
testcase_34 AC 297 ms
30,288 KB
testcase_35 AC 297 ms
30,212 KB
testcase_36 AC 299 ms
30,264 KB
testcase_37 AC 298 ms
30,320 KB
testcase_38 AC 298 ms
30,276 KB
testcase_39 AC 296 ms
30,196 KB
testcase_40 AC 297 ms
30,244 KB
testcase_41 AC 297 ms
30,204 KB
testcase_42 AC 297 ms
30,408 KB
testcase_43 AC 297 ms
30,496 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 modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		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){
        if (N % b == 0){
          prev[b].push_back(a);
          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