跳到正文

个人记录

暑假-S组-第一场总结

ypz_HC约 5 分钟
原文
文章信息与版本

文章信息

发布
2025年8月14日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 5 分钟

版本

  1. v1当前

T1

  1. 第一题我们可以从中找规律,利用二进制的性质,找到需要删的人数。
  2. 答案为删除人数*2+1。
  3. 错因:忘记判断n-lowbit(n)为0的情况。
C++
#include<bits/stdc++.h>
using namespace std;
int t,n;
int lowbit(int x){
	return (x&(-x));
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--){
		cin>>n;
		int sum=0;
		while(n-lowbit(n)!=0){
			sum+=lowbit(n);
			n-=lowbit(n);
		} 
		cout<<sum*2+1<<"\n";
	}
	return 0;
}

T2

  1. 这题我们可以发现他每次不是乘3就是乘2。
  2. 所以我们可以用差分数组来记录2和3出现的次数。
  3. 错因:写暴力被诈骗了。
C++
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1004535809;
const int maxn=1e5+7;
int diff2[maxn];
int diff3[maxn];
int T;
int cal(int x,int a,int b){
    for (int i=1;i<=b;i++){
        x*=a;
        x%=mod;
    }
    return x;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>T;
    while(T--){
        memset(diff2,0,sizeof(diff2));
        memset(diff3,0,sizeof(diff3));
        int n,m;
        cin>>n>>m;
        for (int i=1;i<=m;i++){
            int l,r,x;
            cin>>l>>r>>x;
            if(x==2){
                diff2[l]+=1;
                diff2[r+1]-=1;
            }
            if(x==3{
                diff3[l]+=1;
                diff3[r+1]-=1;
            }
        }
        int minn2=diff2[1];
        int minn3=diff3[1];
        int ans=1;
        for(int i=2;i<=n;i++){
            diff2[i]+=diff2[i-1];
            diff3[i]+=diff3[i-1];
            minn2=min(minn2,diff2[i]);
            minn3=min(minn3,diff3[i]);
        }
        ans=cal(ans,2,minn2);
        ans=cal(ans,3,minn3);
        cout<<ans<<"\n";
    }
    return 0;
}

T3

  1. 这是一道结论推导题,结论是这个cnt=(cnt+((ans[n]-ans[n-i]-ans[i-1]+mod)%mod*w[i])%mod)%mod;
  2. 记得步步取模。
  3. 错因:暴力超时。
C++
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
#define int long long
int n,m,a[300005],w[300005],sum[300005],ans[300005];
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum[i]=(sum[i-1]+a[i])%mod;
	}
	for(int i=1;i<=n;i++){
		cin>>w[i];
	}
	for(int i=1;i<=n;i++){
		ans[i]=(ans[i-1]+sum[i])%mod;
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		cnt=(cnt+((ans[n]-ans[n-i]-ans[i-1]+mod)%mod*w[i])%mod)%mod;
	}
	cout<<cnt%mod;
	return 0;
}
原文