9.23赛后总结
liuyi0905
·
·
个人记录
成绩:
(题目按做题顺序排列)
## T1:
先暴搜打了个表,然后分类讨论每一种情况,找规律。\
$80$ pts,用时 $50$ min,死因:没开 `long long`。。。
```cpp
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
int t;
bool W(LL a,LL b,LL c){
if(!b&&!c){
return 0;
}
if(!a&&!b){
return c==1;
}
if(!a&&!c){
return b==1;
}
if(!a){
return 1;
}
if(!b||!c){
return (a+(!b?c==1:b==1))%2;
}
return a%2==0||abs(b-c)>1;
}
int main(){
freopen("yiyi.in","r",stdin);
freopen("yiyi.out","w",stdout);
cin>>t;
for(LL a,b,c;t;t--){
cin>>a>>b>>c;
cout<<(W(a,b,c)?"First":"Second")<<"\n";
}
return 0;
}
```
## T2:
也是最开始暴力打了个表,没有发现什么规律。又发现 $n$ 的范围不大,所以应该要用到循环,所以开始推公式,但是没有推出来吗,用时 $40$ min,果断跳过。
```cpp
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
const int N=1e6+5,M=998244353;
int n,p[N];
LL f[N];
LL P(LL x,LL y){
LL s=1;
for(;y;x=x*x%M,y>>=1){
y&1&&(s=s*x%M);
}
return s;
}
LL C(int p[]){
for(int i=1;i<=n;i++){
if(i>p[i]){
return i;
}
}
return n+1;
}
LL W(){
LL s=0;
iota(p+1,p+n+1,1);
do{
s=(s+C(p))%M;
}while(next_permutation(p+1,p+n+1));
return s;
}
int main(){
freopen("wuyi.in","r",stdin);
freopen("wuyi.out","w",stdout);
cin>>n,f[0]=1;
for(int i=1;i<=n;i++){
f[i]=f[i-1]*i%M;
}
cout<<W()*P(f[n],M-2)%M;
return 0;
}
```
正确思路:
若这个排列最早出现 $i>a_i$ 在 $i$,令 $k=n-i+1$,则前 $i-1$ 个数的方案数为(过程略):
$$\sum\limits_{j=1}^i(k+1)^{i-j-1}k^j=k[(k+1)^{n-k}-k^{n-k}]$$
所以 $val(p)$ 的总和为(过程略):
$$\sum\limits_{i=1}^n(n-i+1)\times i!\times[(i+1)^{n-i}-i^{n-i}]$$
用有理数取余计算一下答案即可。
```cpp
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
const int N=1e6+5,M=998244353;
int n;
LL f[N];
LL C(LL x,LL y){
LL s=1;
for(;y;x=x*x%M,y>>=1){
y&1&&(s=s*x%M);
}
return s;
}
int main(){
freopen("wuyi.in","r",stdin);
freopen("wuyi.out","w",stdout);
cin>>n,f[0]=1;
for(int i=1;i<=n;i++){
f[i]=f[i-1]*i%M;
}
LL s=n+1;
for(int i=1;i<=n;i++){
s=(s+(n-i+1)*f[i]%M*(C(i+1,n-i)-C(i,n-i)+M)%M)%M;
}
cout<<s*C(f[n],M-2)%M;
return 0;
}
```
## T3:
打了个暴力,$30$ pts。
正确代码:
```cpp
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
const int N=1e7+5,M=105;
int t,m;
LL f[M];
unordered_map<LL,LL>p;
void I(){
f[++m]=1;
for(;f[m]<=1e18;){
m++,f[m]=f[m-2]+f[m-1];
}
}
LL S(LL x){
if(!x){
return 0;
}
if(p.count(x)){
return p[x];
}
int k=upper_bound(f+1,f+m+1,x)-f-1;
return p[x]=S(f[k]-1)^S(x-f[k])^((x-f[k]+1)%2?f[k]:0);
}
int main(){
freopen("yijiu.in","r",stdin);
freopen("yijiu.out","w",stdout);
I(),cin>>t;
for(LL l,r;t;t--){
cin>>l>>r;
cout<<(S(r)^S(l-1))<<"\n";
}
return 0;
}
```
## T4:
打了个暴力背包,但在比赛快结束的时候,不小心又把代码改成错的了,$0$ pts。