結果

問題 No.2443 特殊線形群の標準表現
ユーザー momoyuumomoyuu
提出日時 2023-08-25 22:51:31
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,970 ms / 3,000 ms
コード長 3,291 bytes
コンパイル時間 3,512 ms
コンパイル使用メモリ 262,604 KB
実行使用メモリ 71,764 KB
最終ジャッジ日時 2023-08-25 22:51:48
合計ジャッジ時間 16,622 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 14 ms
4,380 KB
testcase_14 AC 159 ms
10,920 KB
testcase_15 AC 1,946 ms
71,684 KB
testcase_16 AC 1,959 ms
71,592 KB
testcase_17 AC 1,938 ms
71,616 KB
testcase_18 AC 1,902 ms
71,492 KB
testcase_19 AC 1,970 ms
71,764 KB
testcase_20 AC 1,485 ms
71,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

ll mod;
//const ll mod = 998'244'353;
//const ll mod = 1'000'000'007;
//const ll mod = 67'280'421'310'721;
struct mint{
    long long x;
    mint(long long x=0):x((x%mod+mod)%mod){}
    mint operator-() const{
        return mint(-x);
    }
    mint& operator+=(const mint& a){
        if((x+=a.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator-=(const mint& a){
        if((x+=mod-a.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator*=(const  mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    mint pow(long long n) const {
        assert(0 <= n);
        mint a = *this, r = 1;
        while (n) {
            if (n & 1) r *= a;
            a *= a;
            n >>= 1;
        }
        return r;
    }
    mint inv() const{
        return pow(mod-2);
    }
    mint& operator/=(const mint& a){
        return (*this)*=a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    bool operator==(const mint& a) const {
        return x == a.x;
    }
    bool operator<(const mint& a) const{
        return x < a.x;
    }
};

template< typename T >
vector<vector<T>> mattimes(vector<vector<T>> &A,vector<vector<T>> &B){
    assert(A.size()==B.size());
    int n = A.size();
    vector<vector<T>> res(n,vector<T>(n,0));
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)for(int k=0;k<n;k++)res[i][j]+=A[i][k]*B[k][j];
    return res;
}

template< typename T >
vector<T> mattimes(vector<vector<T>> &A,vector<T> &B){
    assert(A.size()==B.size());
    int n = A.size();
    vector<T> res(n,0);
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)res[i]+=A[i][j]*B[j];
    return res;
}

template< typename T >
vector<vector<T>> matpow(vector<vector<T>> a,ll k){
    int n = a.size();
    vector<vector<T>> res(n,vector<T>(n,0));
    for(int i=0;i<n;i++)res[i][i] = T(1);
    for(;k;k>>=1){
        if(k&1) res = mattimes<T>(res,a);
        a = mattimes<T>(a,a);
    }
    return res;
}
#include<atcoder/segtree>
using dat = vector<vector<mint>>;
dat op(dat b,dat a){
    return mattimes<mint>(a,b);
}
dat e(){
    vector<vector<mint>> a(2,vector<mint>(2,0));
    a[0][0] = a[1][1] = 1;
    return a;
}

int main(){
    int n,q;
    cin>>n>>mod>>q;
    vector<vector<vector<mint>>> a(n,vector<vector<mint>>(2,vector<mint>(2,0)));
    atcoder::segtree<dat,op,e> seg(n);
    for(int i = 0;i<n;i++){
        for(int j = 0;j<2;j++){
            for(int k = 0;k<2;k++){
                ll b;
                cin>>b;
                a[i][j][k] = b;
            }
        }
        seg.set(i,a[i]);
    }
    while(q--){
        ll l,r,x,y;
        cin>>l>>r>>x>>y;
        auto now = seg.prod(l,r);
        vector<mint> aa(2);
        aa[0] = x;
        aa[1] = y;
        auto ans = mattimes<mint>(now,aa);
        cout<<ans[0]<<" "<<ans[1]<<endl;
    }

}
0