D. XOR Determinant
You are given two arrays b and c of length n, consisting of non-negative integers. Construct n × n matrix
A as Aij = bi ⊕ cj . Find the determinant of A modulo 998 244 353
考虑
A
i
j
=
∑
k
b
i
,
k
c
j
,
k
+
p
A_{ij}=\sum_k b_{i,k}{c_{j,k}}+p
Aij=∑kbi,kcj,k+p
其中
c
j
,
k
c_{j,k}
cj,k为
c
j
c_j
cj二进制第k位,
b
i
,
k
b_{i,k}
bi,k为
b
i
b_i
bi二进制第k位为1时,为
2
k
2^k
2k,否则为
−
1
-1
−1,并令
p
+
=
2
k
p+=2^k
p+=2k。
这样等价于矩阵每一位都可以用
c
i
c_i
ci线性表示。
l
o
g
2
m
a
x
a
i
=
60
log_2max{a_i}=60
log2maxai=60
考虑第一列前62行,至少有一行可以写成其他61行的线性表示且系数与
c
i
c_i
ci无关,所以该行其他列也可以用同列相同线性表示。也就是这一行可以由其它行线性表示得到。
因此矩阵
r
a
n
k
<
=
61
rank<=61
rank<=61
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (998244353)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
ll pow2(ll a,int b,ll p) //a^b mod p
{
if (b==0) return 1%p;
if (b==1) return a%p;
ll c=pow2(a,b/2,p)%p;
c=c*c%p;
if (b&1) c=c*a%p;
return c%p;
}
ll inv(ll a,ll p) { //gcd(a,p)=1
return pow2(a,p-2,p);
}
#define MAXN (100)
struct M
{
int n,m;
ll a[MAXN][MAXN];
M(int _n=0){n=m=_n;MEM(a);}
M(int _n,int _m){n=_n,m=_m;MEM(a);}
void mem (int _n=0){n=m=_n;MEM(a);}
void mem (int _n,int _m){n=_n,m=_m;MEM(a);}
ll mat[MAXN][MAXN],tmp[MAXN];
ll det()
{
For(i,n) For(j,m) mat[i][j]=a[i][j]%F;
ll ans=1;
For(i,n)
{
int pos=i;
while (mat[pos][i]==0&&pos<n) ++pos;
if (mat[pos][i]==0) continue;
if (pos^i)
{
copy(mat[pos]+1,mat[pos]+1+m+1,tmp+1);
copy(mat[i]+1,mat[i]+1+m+1,mat[pos]+1);
copy(tmp+1,tmp+1+m+1,mat[i]+1);
ans=sub(0,ans);
}
ll invmatii=inv(mat[i][i],F);
Fork(j,i+1,n)
if (i^j)
{
ll p = mul(mat[j][i],invmatii);
For(k,m) mat[j][k]=sub(mat[j][k],mul(mat[i][k],p));
}
}
For(i,n) ans=mul(ans,mat[i][i]);
return ans;
}
}A;
#define eps 1e-6
struct M2
{
int n,m;
ll a[MAXN][MAXN];
M2(int _n=0){n=m=_n;MEM(a);}
M2(int _n,int _m){n=_n,m=_m;MEM(a);}
void mem (int _n=0){n=m=_n;MEM(a);}
void mem (int _n,int _m){n=_n,m=_m;MEM(a);}
long double mat[MAXN][MAXN],tmp[MAXN];
long double det()
{
For(i,n) For(j,m) mat[i][j]=a[i][j];
For(i,n)
{
int pos=i;
while (fabs(mat[pos][i])<eps&&pos<n) ++pos;
if (fabs(mat[pos][i])<eps) continue;
if (pos^i)
{
copy(mat[pos]+1,mat[pos]+1+m+1,tmp+1);
copy(mat[i]+1,mat[i]+1+m+1,mat[pos]+1);
copy(tmp+1,tmp+1+m+1,mat[i]+1);
}
Fork(j,i+1,n)
if (i^j)
{
long double p = mat[j][i]/mat[i][i];
For(k,m) mat[j][k]-=mat[i][k]*p;
}
}
long double ans=1;
For(i,n) ans*=mat[i][i];
return ans;
}
}A2;
int main()
{
// freopen("D.in","r",stdin);
int T;
cin>>T;
while(T--) {
int n;
cin>>n;
if(n>=100) {
For(i,2*n)read();
puts("0");
}
else {
ll b[100],c[100];
For(i,n) cin>>b[i];
For(i,n) cin>>c[i];
A.mem(n);
For(i,n) For(j,n) A.a[i][j]=(b[i]^c[j])%F;
cout<<A.det()<<endl;
}
}
return 0;
}
E. Egor Has a Problem
显然
a
q
/
a
p
≥
1
a_q/a_p\ge 1
aq/ap≥1,由于
max
a
i
\max{a_i}
maxai不大,故存在上界
c
c
c,前
c
c
c个数里一定有至少2组相邻对
a
q
/
a
p
=
1
a_q/a_p=1
aq/ap=1
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int n;
ll a[500100];
void work() {
For(i,n) Fork(j,i+1,n) Fork(k,j+1,n) Fork(l,k+1,n) {
if(a[j]/a[i]==a[l]/a[k]){
puts("YES");
printf("%d %d %d %d\n",i,j,k,l);
return;
}
}
puts("NO");
}
void work2() {
vector<int> v;
For(i,n-1) {
if(a[i+1]/a[i]==1) {
v.pb(i);
}
}
int sz=v.size();
if(sz>=2 && v[0]+1<v[sz-1]){
puts("YES");
printf("%d %d %d %d\n",v[0],v[0]+1,v[sz-1],v[sz-1]+1);
}
else puts("NO");
}
int main()
{
// freopen("E.in","r",stdin);
// freopen(".out","w",stdout);
n=read();
For(i,n) cin>>a[i];
if(n<=30) work();
else work2();
return 0;
}