結果

問題 No.2443 特殊線形群の標準表現
ユーザー bortikbortik
提出日時 2023-08-25 22:49:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 492 ms / 3,000 ms
コード長 1,908 bytes
コンパイル時間 2,020 ms
コンパイル使用メモリ 201,344 KB
実行使用メモリ 12,584 KB
最終ジャッジ日時 2023-08-25 22:49:17
合計ジャッジ時間 7,316 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 47 ms
4,380 KB
testcase_15 AC 492 ms
12,468 KB
testcase_16 AC 461 ms
12,392 KB
testcase_17 AC 487 ms
12,352 KB
testcase_18 AC 464 ms
12,484 KB
testcase_19 AC 472 ms
12,584 KB
testcase_20 AC 443 ms
12,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, n, a) for (int i = (int)(n); i >= (int)(a); i--)

ll b;

ll positive_modulo(ll i, ll n) {
        return (i % n + n) % n;
}
void mult(ll m1[2][2], ll m2[2][2], ll result[2][2]){
    result[0][0] = positive_modulo(m1[0][0]*m2[0][0]+m1[0][1]*m2[1][0],b);
    result[0][1] = positive_modulo(m1[0][0]*m2[0][1]+m1[0][1]*m2[1][1],b);
    result[1][0] = positive_modulo(m1[1][0]*m2[0][0]+m1[1][1]*m2[1][0],b);
    result[1][1] = positive_modulo(m1[1][0]*m2[0][1]+m1[1][1]*m2[1][1],b);
}


void solve(){
    int n,q; cin >> n >> b >> q;
    vector<ll[2][2]> A(n+1);
    vector<ll[2][2]> Ap(n+1);
    vector<ll[2][2]> Ainv(n+1);
    Ainv[0][0][0] = 1;
    Ainv[0][0][1] = 0;
    Ainv[0][1][0] = 0;
    Ainv[0][1][1] = 1;
    Ap[0][0][0] = 1;
    Ap[0][0][1] = 0;
    Ap[0][1][0] = 0;
    Ap[0][1][1] = 1;
    rep(i,1,n+1){
        cin >> A[i][0][0] >> A[i][0][1];
        cin >> A[i][1][0] >> A[i][1][1];
        mult(A[i], Ap[i-1], Ap[i]);
        Ainv[i][0][0] = Ap[i][1][1];
        Ainv[i][0][1] = -Ap[i][0][1];
        Ainv[i][1][0] = -Ap[i][1][0];
        Ainv[i][1][1] = Ap[i][0][0];
    }
    for(int i = 0; i < q; i++){
        ll L,R,x,y; cin >> L >> R >> x >> y;
        ll mat[2][2];
        mult(Ap[R], Ainv[L], mat);
        ll z = positive_modulo(mat[0][0]*x+mat[0][1]*y,b);
        ll w = positive_modulo(mat[1][0]*x+mat[1][1]*y,b);
        cout << z << " " << w << endl;
        //cout << " no "<<mat[0][0] << " " << mat[0][1] << endl;
        //cout << "prod "<<Ap[R][0][0]<<" " << Ap[R][0][1]<<endl<< Ap[R][1][0]<< " " << Ap[R][1][1]<<endl;
        //cout << "inv " <<Ainv[L][0][0]<< " " << Ainv[L][0][1]<<endl<< Ainv[L][1][0]<<" "<< Ainv[L][1][1]<<endl;
    }

}

int main(){

    int t = 1;
    //cin >> t;
    rep(i,0,t) solve();

    return 0;
}
0