結果
問題 | No.2443 特殊線形群の標準表現 |
ユーザー |
![]() |
提出日時 | 2023-08-25 21:39:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,734 ms / 3,000 ms |
コード長 | 2,315 bytes |
コンパイル時間 | 4,849 ms |
コンパイル使用メモリ | 268,676 KB |
最終ジャッジ日時 | 2025-02-16 13:51:18 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <stdio.h>#include <atcoder/all>#include <bits/stdc++.h>using namespace std;using namespace atcoder;using mint = modint;#define rep(i,n) for (int i = 0; i < (n); ++i)#define Inf32 1000000001#define Inf64 4000000000000000001template <class S,S (*op0)(S, S),S (*e0)(),S (*op1)(S, S),S (*e1)()>struct matrix{vector<vector<S>> v;int _h,_w;matrix(vector<vector<S>> X){v = X;_h = X.size();_w = 0;if(X.size()>0)_w = X[0].size();}matrix(int h,int w){v.resize(h,vector<S>(w,e0()));_h = h;_w = w;}void add_element(int from,int to,S x){v[to][from] = op0(v[to][from],x);}matrix e(){assert(_h==_w);matrix<S,op0,e0,op1,e1> ret(_h,_w);for(int i=0;i<_h;i++){for(int j=0;j<_w;j++){if(i==j)ret.v[i][j] = e1();else ret.v[i][j] = e0();}}return ret;}matrix &operator*=(const matrix &another){matrix<S,op0,e0,op1,e1> ret(_h,another._w);for(int i=0;i<_h;i++){for(int j=0;j<another._w;j++){ret.v[i][j] = e0();for(int k=0;k<_w;k++){ret.v[i][j] = op0(ret.v[i][j],op1(v[i][k],another.v[k][j]));}}}v = ret.v;return (*this);}matrix operator*(const matrix &another)const{return (matrix(*this)*=another);}matrix pow(long long cnt){matrix<S,op0,e0,op1,e1> ret = e();auto temp = *this;while(cnt!=0LL){if((cnt&1)==1){ret *= temp;}temp *= temp;cnt>>=1;}return ret;}};mint op0(mint a,mint b){return a+b;}mint e0(){return 0;}mint op1(mint a,mint b){return b*a;}mint e1(){return 1;}matrix<mint,op0,e0,op1,e1> op(matrix<mint,op0,e0,op1,e1> a,matrix<mint,op0,e0,op1,e1> b){return b*a;}matrix<mint,op0,e0,op1,e1> e(){matrix<mint,op0,e0,op1,e1> ret(2,2);return ret.e();}int main(){int N,B,Q;cin>>N>>B>>Q;mint::set_mod(B);vector<matrix<mint,op0,e0,op1,e1>> a(N,matrix<mint,op0,e0,op1,e1>(2,2));rep(i,N){rep(j,2){rep(k,2){int t;cin>>t;a[i].v[j][k] = t;}}}segtree<matrix<mint,op0,e0,op1,e1>, op,e> seg(a);rep(_,Q){int L,R,x,y;cin>>L>>R>>x>>y;matrix<mint,op0,e0,op1,e1> t(2,1);t.v[0][0] = x;t.v[1][0] = y;t = seg.prod(L,R) * t;cout<<t.v[0][0].val()<<' '<<t.v[1][0].val()<<endl;}return 0;}