結果
問題 | No.426 往復漸化式 |
ユーザー | pekempey |
提出日時 | 2016-09-23 03:04:20 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,167 bytes |
コンパイル時間 | 1,644 ms |
コンパイル使用メモリ | 165,416 KB |
実行使用メモリ | 42,684 KB |
最終ジャッジ日時 | 2024-04-28 20:31:56 |
合計ジャッジ時間 | 4,310 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
42,520 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 60 ms
42,376 KB |
testcase_12 | AC | 83 ms
42,624 KB |
testcase_13 | AC | 98 ms
42,468 KB |
testcase_14 | AC | 83 ms
42,488 KB |
testcase_15 | AC | 65 ms
42,464 KB |
testcase_16 | AC | 94 ms
42,540 KB |
testcase_17 | AC | 108 ms
42,624 KB |
testcase_18 | AC | 93 ms
42,624 KB |
testcase_19 | AC | 54 ms
42,540 KB |
testcase_20 | AC | 73 ms
42,600 KB |
testcase_21 | AC | 85 ms
42,624 KB |
testcase_22 | AC | 73 ms
42,532 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:117:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 117 | for (int i = 0; i < 3; i++) scanf("%lld", &va[i][0]); | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:118:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 118 | for (int i = 0; i < 2; i++) scanf("%lld", &vb[i][0]); | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:131:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 131 | scanf("%d", &k); | ~~~~~^~~~~~~~~~ main.cpp:133:66: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 133 | for (int j = 0; j < 3; j++) scanf("%lld", &seg[k + N].A[i][j]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:138:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 138 | scanf("%d", &k); | ~~~~~^~~~~~~~~~ main.cpp:140:66: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 140 | for (int j = 0; j < 2; j++) scanf("%lld", &seg[k + N].B[i][j]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:144:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 144 |
ソースコード
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; template<int H, int W> struct Matrix { long long a[H][W] = {}; static Matrix I() { Matrix<H, W> res; for (int i = 0; i < H; i++) res[i][i] = 1; return res; } Matrix operator+(const Matrix<H, W> &b) const { Matrix<H, W> s; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { s.a[i][j] = a[i][j] + b.a[i][j]; if (s.a[i][j] >= mod) s.a[i][j] -= mod; } } return s; } template<int N> Matrix<H, N> operator*(const Matrix<W, N> &b) const { Matrix<H, N> s; const long long modl = 8 * mod * mod; for (int i = 0; i < H; i++) { for (int k = 0; k < W; k++) { for (int j = 0; j < N; j++) { s[i][j] += a[i][k] * b.a[k][j]; if (s[i][j] >= modl) s[i][j] -= modl; } } for (int j = 0; j < N; j++) s[i][j] %= mod; } return s; } long long *operator[](int i) { return a[i]; } }; const int N = 1 << 17; struct Tuple { Matrix<3, 3> A; Matrix<2, 2> B; Matrix<2, 3> S; Tuple() { A = Matrix<3, 3>::I(); B = Matrix<2, 2>::I(); } Tuple(Matrix<3, 3> A, Matrix<2, 2> B, Matrix<2, 3> S) : A(A), B(B), S(S) {} Tuple operator*(const Tuple &r) const { return Tuple(r.A * A, B * r.B, S + B * r.S * A); } }; Tuple seg[N * 2]; void build() { for (int k = 0; k < N; k++) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { seg[k + N].S[i][j] = k * 6 + i * 3 + j; } } for (int i = 0; i < 3; i++) seg[k + N].A[i][i] = 1; for (int i = 0; i < 2; i++) seg[k + N].B[i][i] = 1; } for (int k = N - 1; k > 0; k--) { seg[k] = seg[k * 2 + 0] * seg[k * 2 + 1]; } } void update(int k) { k += N; while (k > 1) { k >>= 1; seg[k] = seg[k * 2 + 0] * seg[k * 2 + 1]; } } Tuple query(int l, int r) { Tuple L, R; for (l += N, r += N; l < r; l >>= 1, r >>= 1) { if (l & 1) L = L * seg[l++]; if (r & 1) R = seg[--r] * R; } return L * R; } // I6 A0 A1 | A2 A3 A4 A5 // I5 A0 A1 | A2 A3 A4 // I4 A0 A1 | A2 A3 // I3 A0 A1 | A2 // ------------------------------- // I2 A0 A1 // I1 A0 int main() { int n; cin >> n; Matrix<3, 1> va; Matrix<2, 1> vb; for (int i = 0; i < 3; i++) scanf("%lld", &va[i][0]); for (int i = 0; i < 2; i++) scanf("%lld", &vb[i][0]); build(); int q; cin >> q; for (int ii = 0; ii < q; ii++) { string s; cin >> s; if (s == "a") { int k; scanf("%d", &k); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) scanf("%lld", &seg[k + N].A[i][j]); } update(k); } else if (s == "b") { int k; scanf("%d", &k); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) scanf("%lld", &seg[k + N].B[i][j]); } } else if (s == "ga") { int k; scanf("%d", &k); auto ans = query(0, k).A * va; for (int i = 0; i < 3; i++) { printf("%lld ", ans[i][0]); } printf("\n"); fflush(stdout); } else if (s == "gb") { int k; scanf("%d", &k); auto X = query(k + 1, n + 1); auto Y = query(0, k + 1); auto ans = X.B * vb + X.S * Y.A * va; for (int i = 0; i < 2; i++) { printf("%lld ", ans[i][0]); } printf("\n"); fflush(stdout); } } }