跳到正文

个人记录

正睿CSP 7连测 day5(2023.10.3)

xuantianhao约 8 分钟
原文
文章信息与版本

文章信息

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

版本

  1. v1当前

题解

T1

原神

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+100;
int n,m,x,cnt1,cnt2,res;
int a[N],b[N];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(x%2==0) a[++cnt1]=x;
	}
	cin>>m;
	for(int i=1;i<=m;i++){
		cin>>x;
		if(x%2==1) cnt2++;
	}
	sort(a+1,a+cnt1+1);
	for(int i=1;i<=cnt1-cnt2;i++) res+=a[i];
	cout<<res;
	return 0;
} 

T2

方舟

没做出来

C++
#include <bits/stdc++.h>
using namespace std;
typedef long long Int;
const int N=1e6+5;
Int n,m,k,P,c[N],a[N],ans,ans1=1,ans2=1;
unsigned s1, s2, s3;
Int Pow(Int a,Int b)
{
	if (b==0) return 1;
	if (b==1) return a;
	Int t=Pow(a,b/2);
	t=t*t%P;
	if (b&1) t=t*a%P;
	return t;
}
inline unsigned Next(){
	unsigned res;
	s1^=s3,s3+=3055373123u;
	res=s1,s2=(s2^s3)&31;
	s3=(s3>>s2)|((s3<<(31^s2))<<1);
	return res;
}
signed main() 
{
	cin>>n>>m>>k>>P>>s1>>s2>>s3;
	for (int i=1;i<=n;i++)
		c[i]=Next()%m+1,a[i]=Next()%P;
	for (int i=1;i<=n;i++)
		ans1=ans1*Pow(a[i]+1,c[i])%P;
	ans1=ans1*(k+1)%P;
	if (!k) for (int i=1;i<=n;i++) ans2=ans2*Pow(1-a[i],c[i])%P;
	else ans2=0;
	ans=(ans1+ans2+P)%P;
	cout<<ans*Pow(2,P-2)%P<<'\n';
	return 0;
}

T3

铁道

C++
#include<bits/stdc++.h>
using namespace std;
const int N=3e3+100;
int n;
int pre[N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    cin>>n;
    cout<<n*n/4<<'\n';
    for(int i=1;i<=n;i++) pre[i]=n;
    for(int i=1;i<=n;i++){
        for(int j=pre[i];j>i;j--){
            if(pre[j]==j) cout<<i<<' '<<j<<' '<<j<<' '<<j<<'\n';
            else{
            	cout<<i<<' '<<j<<' '<<pre[j]<<' '<<pre[j]<<'\n';
            	pre[j]--;
			}
        }
    }
    return 0;
}

T4

启动

没做,咕

C++
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
using namespace std;
const LL P[]={0,2,3,5,7,11,13,17,19,23,29,31,37};
mt19937_64 RAND(chrono::steady_clock().now().time_since_epoch().count());
LL Rand(LL l,LL r){
	return RAND()%(r-l+1)+l;
}
LL power(__int128 a,__int128 b,LL mod){
	__int128 ans=1;
	while(b){
		if(b&1){
			ans=ans*a%mod;
		}
		a=a*a%mod;
		b=b>>1;
	}
	return ans;
}
bool check(LL a,LL p){
	if(a==p){
		return 1;
	}
	if(power(a,p-1,p)!=1){
		return 0;
	}
	LL d=p-1;
	while(!(d&1)){
		d>>=1;
		LL tmp=power(a,d,p);
		if(tmp==p-1){
			return 1;
		}
		else{
			if(tmp!=1){
				return 0;
			}
		}
	}
	return 1;
}
bool is_prime(LL p){
	for(LL i=1;i<=12;i++){
		if(!check(P[i],p)){
			return 0;
		}
	}
	return 1;
}
vector<LL > fac;
LL f(LL x,LL c,LL p){
	return ((__int128)x*x+c)%p;
}
void getprime(LL p){
	if(is_prime(p)){
		fac.pb(p);
		return;
	}
	while(1){
		LL c=Rand(1,p),x=Rand(0,p-1),y=f(x,c,p);
		for(LL i=1;x!=y;i=min(128ll,(i<<1))){
			LL cur=1;
			for(LL j=1;j<=i;j++){
				LL tmp=(__int128)cur*abs(y-x)%p;
				if(!tmp){
					break;
				}
				cur=tmp;
				x=f(x,c,p);
				y=f(f(y,c,p),c,p);
			}
			LL tmp=__gcd(cur,p);
			if(tmp>1){
				getprime(tmp);
				getprime(p/tmp);
				return;
			}
		}
	}
}
LL T,n;
vector<LL>m,a,phi;
LL res,mod,M[1010],t[1010];
void check(){
	mod=1;
	for(auto x:m){
		mod*=x;
	}
	for(LL i=0;i<m.size();i++){
		M[i]=mod/m[i];
		t[i]=power(M[i],phi[i]-1,m[i]);
	}
	LL sum=0;
	for(LL i=0;i<m.size();i++){
		sum=(sum+(__int128)a[i]*M[i]%mod*t[i]%mod)%mod;
	}
	LL k=(n-1-sum+mod-1)/mod-1;
	res=max(res,k*mod+sum);
}
void solve(LL dep){
	if(dep>=m.size()){
		check();
		return;
	}
	a.push_back(1);
	solve(dep+1);
	a.pop_back();
	a.push_back(m[dep]-1);
	solve(dep+1);
	a.pop_back();
}
signed main(){
	cin>>T;
	while(T--){
		cin>>n;
		fac.clear();
		getprime(n);
		sort(fac.begin(),fac.end());
		m.clear();
		a.clear();
		phi.clear();
		for(LL i=0,j=0;i<fac.size();i=j){
			LL cur=1;
			while(j<fac.size()&&fac[i]==fac[j]){
				j++;
				cur*=fac[i];
			}
			m.push_back(cur);
			phi.push_back(cur/fac[i]*(fac[i]-1));
		}
		if(m[0]>4&&m[0]%2==0){
			m[0]=m[0]/2;
		}
		res=1;
		solve(0);
		cout<<res<<endl;
	}
}
原文