跳到正文

个人记录

Voidr

Void_Rift约 4 分钟
原文

这是 2026年10月11日 存档的第 4 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年10月3日
收录
2026年10月3日
更新
2026年11月14日
篇幅
约 4 分钟

版本

  1. v6当前
  2. v5
  3. v4
  4. v3
更早的 2 个版本
  1. v2
  2. v1

26.10.4

T3

C++
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
using namespace std;
const int N=2e5+10,maxl=1e2+10,inf=0x3f3f3f3f3f3f,mod=1e9+7;
int T,n,m,k;
int a[N],cnt[N],fac[N],inv[N];
int quick_pow(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1) res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int C(int x,int y)
{
	if(y>x || y<0) return 0;
	return ((fac[x]*inv[y])%mod*inv[x-y])%mod;
}
void init()
{
	fac[0]=inv[0]=1;
	for(int i=1;i<=(int)2e5;i++) fac[i]=(fac[i-1]*i)%mod;
	for(int i=1;i<=(int)2e5;i++) inv[i]=quick_pow(fac[i],mod-2);
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    init();
    cin>>T;
    while(T--)
    {
    	cin>>n>>m>>k;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>a[i];
    		cnt[a[i]]++;
		}
    	for(int i=1;i<=n;i++) cnt[i]+=cnt[i-1];
    	sort(a+1,a+n+1);
    	int ans=0;
    	for(int i=n;i>=1;i--) 
    	{
    		ans+=((a[i]>k)? C(i-cnt[a[i]-k-1]-1,m-1):C(i-1,m-1));
    		ans%=mod;
		}
		cout<<(ans%mod)<<"\n";
		for(int i=0;i<=n+1;i++) cnt[i]=0;
	}
    return 0;
}

T4

C++
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
using namespace std;
const int N=1e6+10,maxl=1e3+10,inf=0x3f3f3f3f3f3f,mod=1e9+7;
int k,q;
int dp[N];
string s;
char t[N];
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin>>k>>s;
    k=(1<<k);
    for(int i=1;i<=k-1;i++) t[k-i]=s[i-1];
    for(int i=k;i<=2*k-1;i++) dp[i]=1;
    for(int i=k-1;i>=1;i--)
    {
        if(t[i]=='0') dp[i]=dp[2*i+1];
        else if(t[i]=='1') dp[i]=dp[2*i];
        else dp[i]=dp[2*i]+dp[2*i+1];
    }
    cin>>q;
    while(q--)
    {
        int x;
        char c;
        cin>>x>>c;
        int v=k-x;
        t[v]=c;
        while(v>=1)
        {
            if(t[v]=='0') dp[v]=dp[2*v+1];
            else if(t[v]=='1') dp[v]=dp[2*v];
            else dp[v]=dp[2*v]+dp[2*v+1];
            v/=2;
        }
        cout<<dp[1]<<"\n";
    }
    return 0;
}