1002 递归 找规律
//zjx6666
#include<iostream>
using namespace std;
int mod= 998244353;
long long fast(long long x,int y)
{
long long ans=1;
while(y)
{
if(y%2)ans=ans*x%mod;
y=y/2;
x=x*x%mod;
}
return ans;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n,id=0;
cin>>n;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
id=max(x,id);
}
if(id>1)cout<<fast(2,mod-2);//当有堆>1时胜率永远为1/2
else if(n%2)cout<<1;
else cout<<0;
cout<<"\n";
}
return 0;
}
1013 树状数组求逆序对 异或与二进制位的转化
//zjx6666
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=100010;
int s[maxn];
int n;
int low(int x)
{
return x&(-x);
}
void add(int x,int d)
{
while(x<=n)
{
s[x]+=d;
x=x+low(x);
}
}
long long ch(int x)
{
long long ans=0;
while(x)
{
ans=ans+s[x];
x=x-low(x);
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--)
{
memset(s,0,sizeof(s));
long long c1=0,c2=0;
cin>>n;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
c2=c2+i-ch(x)-1;//树状数组求逆序对
add(x,1);
}
if(n==1)cout<<"0 1"<<"\n";
else
{
if(c2%2)cout<<2<<" ";//因为求异或和最小,考虑两两操作 min=0/2
else cout<<0<<" ";
long long id=1,s=0;
while(id<=n)
{
s=s+id;
id=id*2;
}
//cout<<s<<"!";
if(c2%2)cout<<s<<" ";//最大情况下二进制n位都取1,
//再两两操作奇偶性不变 n(n-1)/2次操作 n=4,8,16...
else cout<<(s^2)<<" ";
cout<<"\n";
}
}
return 0;
}