結果
問題 |
No.3227 Matrix Query
|
ユーザー |
![]() |
提出日時 | 2025-08-11 12:26:00 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,942 ms / 8,000 ms |
コード長 | 2,173 bytes |
コンパイル時間 | 5,837 ms |
コンパイル使用メモリ | 334,776 KB |
実行使用メモリ | 9,600 KB |
最終ジャッジ日時 | 2025-08-11 12:26:42 |
合計ジャッジ時間 | 36,825 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #include <atcoder/all> #define pass (void)0 #define INF (1<<30)-1 #define INFLL (1LL<<60)-1 using namespace std; using namespace atcoder; using mint = modint998244353; using ll = long long; ll K; struct Node { vector<vector<ll>> M; }; Node op(Node left, Node right) { if (left.M[0][0] == -1) return right; if (right.M[0][0] == -1) return left; vector<vector<ll>> M(2, vector<ll> (2, 0)); M[0][0] = (left.M[0][0]*right.M[0][0]%K+left.M[0][1]*right.M[1][0]%K)%K; M[1][0] = (left.M[1][0]*right.M[0][0]%K+left.M[1][1]*right.M[1][0]%K)%K; M[0][1] = (left.M[0][0]*right.M[0][1]%K+left.M[0][1]*right.M[1][1]%K)%K; M[1][1] = (left.M[1][0]*right.M[0][1]%K+left.M[1][1]*right.M[1][1]%K)%K; return Node(M); } Node e() { vector<vector<ll>> M(2, vector<ll> (2, -1)); return Node(M); } int main() { ll N; cin >> K >> N; vector<Node> init(N); for (int i=0; i<N; i++) { ll a, b, c, d; cin >> a >> b; cin >> c >> d; vector<vector<ll>> M(2, vector<ll> (2, 0)); M[0][0] = a; M[0][1] = b; M[1][0] = c; M[1][1] = d; for (int j=0; j<2; j++) { for (int k=0; k<2; k++) { M[j][k] %= K; while (M[j][k] < 0) M[j][k] += K; } } init[i] = Node(M); } segtree<Node, op, e> seg(init); int Q; cin >> Q; for (int i=0; i<Q; i++) { int idx, l, r; cin >> idx >> l >> r; idx --; l --; r --; ll a, b, c, d; cin >> a >> b; cin >> c >> d; vector<vector<ll>> M(2, vector<ll> (2, 0)); M[0][0] = a; M[0][1] = b; M[1][0] = c; M[1][1] = d; for (int j=0; j<2; j++) { for (int k=0; k<2; k++) { M[j][k] %= K; while (M[j][k] < 0) M[j][k] += K; } } seg.set(idx, Node(M)); Node ans = seg.prod(l, r+1); cout << ans.M[0][0] << " " << ans.M[0][1] << endl; cout << ans.M[1][0] << " " << ans.M[1][1] << endl; } }