結果
| 問題 |
No.2443 特殊線形群の標準表現
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2023-08-25 22:51:31 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,849 ms / 3,000 ms |
| コード長 | 3,291 bytes |
| コンパイル時間 | 3,610 ms |
| コンパイル使用メモリ | 265,500 KB |
| 実行使用メモリ | 71,936 KB |
| 最終ジャッジ日時 | 2024-12-24 10:18:23 |
| 合計ジャッジ時間 | 15,803 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#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;
}
}
momoyuu