NOIO T2$\Theta(32(n^3+qn^2))$的倍增矩乘能否过?
  • 板块学术版
  • 楼主Starlight237
  • 当前回复23
  • 已保存回复23
  • 发布时间2020/5/24 13:26
  • 上次更新2023/11/7 01:52:40
查看原帖
NOIO T2$\Theta(32(n^3+qn^2))$的倍增矩乘能否过?
75765
Starlight237楼主2020/5/24 13:26

RT

#include<bits/stdc++.h>
using namespace std;
#define reg register
#define uint unsigned int
extern "C"{
namespace io{
#define IOSIZE 1000000
    static char in[IOSIZE],*p=in,*pp=in,out[IOSIZE],*q=out,ch[20],*t=ch;
    inline char gc(){return p==pp&&(pp=(p=in)+fread(in,1,IOSIZE,stdin),p==pp)?EOF:*p++;}
    inline int read(){
        reg int x=0;reg char ch,f=0;
        while(!isdigit(ch=gc()))f|=ch=='-';
        while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc();
        return f?-x:x;
    }
    inline uint read1(){
        reg uint x=0;reg char ch;
        while(!isdigit(ch=gc()));
        while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc();
        return x;
    }
    inline void write(int x,char sp='\n'){
        x||(*q++=48),x<0&&(*q++='-',x=-x);
        while(x)*t++=x%10+48,x/=10;
        while(t!=ch)*q++=*--t;
        *q++=sp;
    }
    inline void write1(uint x,char sp='\n'){
        x||(*q++=48);
        while(x)*t++=x%10+48,x/=10;
        while(t!=ch)*q++=*--t;
        *q++=sp;
    }
    inline void flush(){fwrite(out,1,q-out,stdout);}
}}
#define rd io::read
#define wt io::write
#define rd1 io::read1
#define wt1 io::write1
inline void work();
int main(){
    freopen("magic.in","r",stdin);
    freopen("magic.out","w",stdout);
    work();
    io::flush();
    return 0;
}
//End of MAIN
const int N=101;
int n,m,q;
uint mp[N][N],f[N],res;
struct mat{
	int n,m;uint a[N][N];
	mat operator*(const mat& b)const{
		mat res;
		res.n=n,res.m=b.m;
        for(reg int i=1;i<=n;++i)
            for(reg int j=1;j<=b.m;++j){
                reg uint tmp=0;
                for(reg int k=1;k<=m;++k)
                    tmp^=(a[i][k]*b.a[k][j]);
                res.a[i][j]=tmp;
            }
        return res;
	}
}A[32],ans;
inline void work(){
	n=rd(),m=rd(),q=rd();
	for(reg int i=1;i<=n;++i)f[i]=rd1();
	for(reg int i=1,u,v;i<=m;++i)
        u=rd(),v=rd(),mp[u][v]=mp[v][u]=1;
	for(reg int i=1;i<=n;++i)
		for(reg int j=1;j<=n;++j)
			A[0].a[i][j]=mp[i][j];
	A[0].n=A[0].m=n;
	ans.n=1,ans.m=n;
	for(reg int i=1;i<32;++i)A[i]=A[i-1]*A[i-1];
	for(reg int x;q;--q){
		x=rd1();
		memset(ans.a,0,sizeof(ans.a));
		for(int i=1;i<=n;++i)ans.a[1][i]=f[i];
		for(int i=0;i<32;++i)((x>>i)&1)&&(ans=ans*A[i],0);
        wt1(ans.a[1][1]);
	}
}

2020/5/24 13:26
加载中...