結果

問題 No.3227 Matrix Query
ユーザー detteiuu
提出日時 2025-08-11 12:19:59
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,947 bytes
コンパイル時間 5,220 ms
コンパイル使用メモリ 334,756 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2025-08-11 12:20:40
合計ジャッジ時間 35,169 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    for (int i=0; i<2; i++) {
        for (int j=0; j<2; j++) {
            while (M[i][j] < 0) M[i][j] += 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;
        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;
        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;
    }
}
0