求调
查看原帖
求调
1127126
yueyan_WZF楼主2025/7/27 17:48
//By yueyan_WZF
#include <bits/stdc++.h>
#define int  long long
using namespace std;
inline int rd(){
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}
const int N=205;
int n,k;
int a[N];
int b[N];
void init(){
    for(int i=0;i<k;i++){
        cin>>a[i];
    }
    for(int i=0;i<k;i++){
        cin>>b[i];
    }
}
struct nod{
    int a[202][202];
}A;
nod Mul(nod x,nod y){
    nod ans;
    for(int i=0;i<k;i++){
        for(int j=0;j<k;j++) ans.a[i][j]=0;
        for(int j=0;j<k;j++){
            for(int p=0;p<k;p++){
                ans.a[i][j]|=(x.a[i][p]&y.a[p][j]);
            }
        }
    }
    return ans;
}
nod power(nod x,int b){
    nod res=A;
  //  cout<<res.a[1][0]<<endl;
    while(b){
        if(b&1){
            res=Mul(res,A);
        }
        A=Mul(A,A);
        b>>=1;
    }
    
    return res;
}
nod mul(nod x){
    nod ans;
    for(int i=0;i<k;i++){
        ans.a[0][i]=0;
        for(int j=0;j<k;j++){
           // cout<<i<<" "<<a[j]<<" "<<x.a[i][j]<<endl;
            ans.a[0][i]|=(a[j]&x.a[j][i]);
        }
    }
    return ans;
}
signed main(){
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    cin>>n>>k;
    init();
    if(n<k){
        cout<<a[n]<<endl;
        return 0;
    }
    for(int i=0;i<k;i++){
        A.a[i][0]=b[i];
        for(int j=1;j<k;j++){
            if(j==i+1){
                A.a[i][j]=-1ll;
            }
            else{
                A.a[i][j]=0ll;
            }
        }
    }
//     for(int i=0;i<k;i++){
//         for(int j=0;j<k;j++) cout<<A.a[i][j]<<" ";
//        cout<<"\n";
//    }
    nod ans=mul(power(A,n-k));
    cout<<ans.a[0][0];
    return 0;
}

2025/7/27 17:48
加载中...