結果
問題 | No.2443 特殊線形群の標準表現 |
ユーザー | hiromi_ayase |
提出日時 | 2023-08-25 22:54:17 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 347 ms / 3,000 ms |
コード長 | 3,965 bytes |
コンパイル時間 | 5,572 ms |
コンパイル使用メモリ | 316,164 KB |
実行使用メモリ | 8,960 KB |
最終ジャッジ日時 | 2024-12-24 10:26:17 |
合計ジャッジ時間 | 9,276 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 5 ms
5,248 KB |
testcase_14 | AC | 33 ms
5,248 KB |
testcase_15 | AC | 347 ms
8,960 KB |
testcase_16 | AC | 344 ms
8,960 KB |
testcase_17 | AC | 345 ms
8,960 KB |
testcase_18 | AC | 337 ms
8,832 KB |
testcase_19 | AC | 344 ms
8,960 KB |
testcase_20 | AC | 293 ms
8,960 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define FAST_IO \ ios::sync_with_stdio(false); \ cin.tie(0); const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; template <typename T, int H, int W> struct Matrix { using Array = array<array<T, W>, H>; Array A; Matrix() : A() { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) (*this)[i][j] = T(); } int height() const { return H; } int width() const { return W; } inline const array<T, W> &operator[](int k) const { return A[k]; } inline array<T, W> &operator[](int k) { return A[k]; } static Matrix I() { assert(H == W); Matrix mat; for (int i = 0; i < H; i++) mat[i][i] = 1; return (mat); } Matrix &operator+=(const Matrix &B) { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) A[i][j] += B[i][j]; return (*this); } Matrix &operator-=(const Matrix &B) { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) A[i][j] -= B[i][j]; return (*this); } Matrix &operator*=(const Matrix &B) { assert(H == W); Matrix C; for (int i = 0; i < H; i++) for (int k = 0; k < H; k++) for (int j = 0; j < H; j++) C[i][j] += A[i][k] * B[k][j]; A.swap(C.A); return (*this); } Matrix &operator^=(long long k) { Matrix B = Matrix::I(); while (k > 0) { if (k & 1) B *= *this; *this *= *this; k >>= 1LL; } A.swap(B.A); return (*this); } Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); } Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); } Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); } Matrix operator^(const long long k) const { return (Matrix(*this) ^= k); } bool operator==(const Matrix &B) const { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (A[i][j] != B[i][j]) return false; return true; } bool operator!=(const Matrix &B) const { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (A[i][j] != B[i][j]) return true; return false; } friend ostream &operator<<(ostream &os, const Matrix &p) { for (int i = 0; i < H; i++) { os << "["; for (int j = 0; j < W; j++) { os << p[i][j] << (j + 1 == W ? "]\n" : ","); } } return (os); } T determinant(int n = -1) { if (n == -1) n = H; Matrix B(*this); T ret = 1; for (int i = 0; i < n; i++) { int idx = -1; for (int j = i; j < n; j++) { if (B[j][i] != 0) { idx = j; break; } } if (idx == -1) return 0; if (i != idx) { ret *= T(-1); swap(B[i], B[idx]); } ret *= B[i][i]; T inv = T(1) / B[i][i]; for (int j = 0; j < n; j++) { B[i][j] *= inv; } for (int j = i + 1; j < n; j++) { T a = B[j][i]; if (a == 0) continue; for (int k = i; k < n; k++) { B[j][k] -= B[i][k] * a; } } } return (ret); } }; using mint = atcoder::modint; int main() { FAST_IO int n,b,q; cin >> n >> b >> q; mint::set_mod(b); using M = Matrix<mint, 2, 2>; auto op = [](M x, M y) { return y * x; }; auto e = []() { M I; I[0][0] = I[1][1] = 1; return I; }; atcoder::segtree<M, op, e> st(n); for (auto i : views::iota(0, n)) { int a1,a2,a3,a4; cin >> a1 >> a2 >> a3 >> a4; M a; a[0][0] = a1; a[0][1] = a2; a[1][0] = a3; a[1][1] = a4; st.set(i, a); } for (auto i : views::iota(0,q)) { int l,r,x,y; cin >> l >> r >> x >> y; M v; v[0][0] = x; v[1][0] = y; auto ret = st.prod(l, r) * v; cout << ret[0][0].val() << " " << ret[1][0].val() << endl; } }