【2020省选模拟】题解
T1:
考场写了个
递归归并的假的复杂度的做法
我是个傻逼
结果还过了90分
把递归然后归并看哪个放前面换成用堆维护即可
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int N=200005;
int v[N],a1[N],a2[N],n;
#define lc (u<<1)
#define rc ((u<<1)|1)
#define mid ((l+r)>>1)
struct Seg{
pii tr[N<<2];
inline pii merge(cs pii &a,cs pii &b){return a.fi<b.fi?a:b;}
void build(int u,int l,int r,int *a){
if(l==r){tr[u].se=l;tr[u].fi=a[l];return;}
build(lc,l,mid,a),build(rc,mid+1,r,a);
tr[u]=merge(tr[lc],tr[rc]);
}
pii query(int u,int l,int r,int st,int des){
if(st<=l&&r<=des)return tr[u];
if(des<=mid)return query(lc,l,mid,st,des);
if(mid<st)return query(rc,mid+1,r,st,des);
return merge(query(lc,l,mid,st,des),query(rc,mid+1,r,st,des));
}
}Seg[2];
#undef lc
#undef rc
#undef mid
struct node{
int l,r,vl,vr;
node(int a=0,int b=0,int c=0,int d=0):l(a),r(b),vl(c),vr(d){}
friend inline bool operator <(cs node &a,cs node &b){
return v[a.vl]>v[b.vl];
}
};
priority_queue<node>q;
inline node get(int l,int r){
pii p=Seg[l&1].query(1,1,n,l,r),q=Seg[(l&1)^1].query(1,1,n,p.se+1,r);
return node(l,r,p.se,q.se);
}
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
// freopen("my.out","w",stdout);
#endif
n=read();
for(int i=1;i<=n;i++){
v[i]=read();
if(i&1)a1[i]=v[i],a2[i]=1e9;
else a2[i]=v[i],a1[i]=1e9;
}
Seg[1].build(1,1,n,a1),Seg[0].build(1,1,n,a2);
q.push(get(1,n));
while(q.size()){
node now=q.top();q.pop();
cout<<v[now.vl]<<" "<<v[now.vr]<<" ";
if(now.l<now.vl)q.push(get(now.l,now.vl-1));
if(now.vl<now.vr-1)q.push(get(now.vl+1,now.vr-1));
if(now.vr<now.r)q.push(get(now.vr+1,now.r));
}
return 0;
}
T2:
普及组数位
嫌麻烦写了个的做法
但好像的还要好写些?
我是个智障
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
ll pw[20];
inline int getin(char c){
if(isdigit(c))return c-'0';
else return 10+c-'A';
}
inline void write(int x){
if(x<10)cout<<x;
else putchar('A'+x-10);
}
namespace solve1{
int dig[20],cnt;
inline void calc1(ll pos,int res){
cnt=0;
while(pos)dig[++cnt]=pos%16,pos/=16;
reverse(dig+1,dig+cnt+1);
write(dig[res]);puts("");
}
inline void solve(ll n){
for(int len=1;;len++){
if(n/len<=pw[len]-pw[len-1]){
return calc1(pw[len-1]+(n-1)/len,(n-1)%len+1);
}
n-=(pw[len]-pw[len-1])*len;
}
}
}
namespace solve2{
ll f[20][2][2],s[20];
int whi;
int dig[20],cnt;
ll dfs(int pos,int lim,int zero){
if(!pos)return 0;
if(f[pos][lim][zero])return f[pos][lim][zero];
ll ret=0;
for(int L=(lim)?dig[pos]:15,i=0;i<=L;i++){
ret+=dfs(pos-1,lim&(i==dig[pos]),zero&(i==0));
if(whi==0&&i==0&&!zero){
if(lim&&i==dig[pos])
ret+=s[pos-1]+1;
else ret+=pw[pos-1];
}
if(whi!=0&&i==whi){
if(lim&&i==dig[pos])
ret+=s[pos-1]+1;
else ret+=pw[pos-1];
}
// cout<<pos<<" "<<i<<" "<<ret<<'\n';
}
return f[pos][lim][zero]=ret;
}
inline void calc2(ll n,int res){
cnt=0;ll pos=n;int anc=0;
while(pos)dig[++cnt]=pos%16,pos/=16;
reverse(dig+1,dig+cnt+1);
for(int i=1;i<=res;i++)if(dig[i]==whi)anc++;
// cout<<anc<<" "<<n-1<<'\n';
cnt=0,pos=n-1;
while(pos)dig[++cnt]=pos%16,pos/=16;
for(int i=1;i<=cnt;i++)s[i]=s[i-1]+dig[i]*pw[i-1];
cout<<anc+dfs(cnt,1,1)<<'\n';
}
inline void solve(ll n){
char ch=gc();
while(isspace(ch))ch=gc();
whi=getin(ch);
memset(f,0,sizeof(f));
for(int len=1;;len++){
if(n/len<=pw[len]-pw[len-1]){
return calc2(pw[len-1]+(n-1)/len,(n-1)%len+1);
}
n-=(pw[len]-pw[len-1])*len;
}
}
}
inline void solve(){
int op=read();
if(op==1)solve1::solve(readll());
else solve2::solve(readll());
}
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
// freopen("my.out","w",stdout);
#endif
pw[0]=1;
for(int i=1;pw[i-1]<=1e18;i++)pw[i]=pw[i-1]*16;
int T=read();
while(T--)solve();
}
T3:
我是个菜逼
完全做不来
设表示有行列且每行都有黑色的方案数
考虑一列一列枚举所有前面列都没有且这列有的行,插入到原来的行中
第二个的系数是因为存在原来行在第列有的情况
所以可以考虑加入行,其中有两个代表原来的行中的
再多设个可以放的位置来处理不存在原来行做开头/结尾的情况
然后就可以了
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int mod=998244353,G=3;
inline int add(int a,int b){return (a+=b)>=mod?(a-mod):a;}
inline int dec(int a,int b){a-=b;return a+(a>>31&mod);}
inline int mul(int a,int b){static ll r;r=1ll*a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
inline void Dec(int &a,int b){a-=b,a+=a>>31&mod;}
inline void Mul(int &a,int b){static ll r;r=1ll*a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
cs int N=32005;
int rev[N];
inline void init_rev(int lim){
for(int i=0;i<lim;i++)rev[i]=(rev[i>>1]>>1)|((i&1)*(lim>>1));
}
inline void ntt(int *f,int lim,int kd){
for(int i=0;i<lim;i++)if(i>rev[i])swap(f[i],f[rev[i]]);
for(int a0,a1,mid=1;mid<lim;mid<<=1){
int wn=ksm(G,(mod-1)/(mid<<1));
for(int i=0;i<lim;i+=mid<<1)
for(int j=0,w=1;j<mid;j++,Mul(w,wn))
a0=f[i+j],a1=mul(f[i+j+mid],w),f[i+j]=add(a0,a1),f[i+j+mid]=dec(a0,a1);
}
if(kd==-1){
reverse(f+1,f+lim);
for(int i=0,iv=Inv(lim);i<lim;i++)Mul(f[i],iv);
}
}
int fac[N],ifac[N];
inline void init_inv(cs int len=N-5){
fac[0]=ifac[0]=1;
for(int i=1;i<=len;i++)fac[i]=mul(fac[i-1],i);
ifac[len]=Inv(fac[len]);
for(int i=len-1;i;i--)ifac[i]=mul(ifac[i+1],i+1);
}
inline int C(int n,int m){return n<m?0:mul(fac[n],mul(ifac[m],ifac[n-m]));}
int lim,n,m,f[N],a[N],g[N];
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
#endif
n=read(),m=read();
lim=1;init_inv();
while(lim<=n*2)lim<<=1;
init_rev(lim);
for(int i=1;i<=n;i++)g[i]=ifac[i+2];
ntt(g,lim,1);
a[0]=1;
for(int i=1;i<=m;i++){
for(int j=0;j<=n;j++)f[j]=mul(a[j],ifac[j]);
ntt(f,lim,1);
for(int j=0;j<lim;j++)Mul(f[j],g[j]);
ntt(f,lim,-1);
for(int j=0;j<=n;j++)a[j]=add(mul(f[j],fac[j+2]),mul(a[j],(1+j+C(j,2))%mod));
for(int j=0;j<lim;j++)f[j]=0;
}
int ret=0;
for(int i=0;i<=n;i++)Add(ret,mul(C(n,i),a[i]));
cout<<ret<<'\n';
}