Loading

CSP 后多校五

A. 集合均值

签到题.

A_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS{
	// #define int long long
	#define lf long double
	#define pb push_back
	#define mp make_pair
	#define lb lower_bound
	#define ub upper_bound
	#define lbt(x) ((x)&(-(x)))
	#define Fill(x,y) memset(x,y,sizeof(x))
	#define Copy(x,y) memcpy(x,y,sizeof(x))
	#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
	auto read=[]()->int{
		int w=0; bool cit=1; char ch;
		while(!isdigit(ch=getchar())) if(ch=='-') cit=0;
		while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar();
		return cit?w:(-w);
	};
} using namespace BSS;

const int mod=998244353,N=1e5+21,M=2e7+21;

int m,n,sum,ans;
int frc[M],inf[M],inv[M];
auto inc=[](int a,int b)->int{ a+=b; return a>=mod ? a-mod : a ; };
auto mul=[](int a,int b)->int{ return 1ll*a*b-1ll*a*b/mod*mod; };
auto ksm=[](int a,int b,int c,int w=1)->int{
	for(a%=c;b;b>>=1,a=1ll*a*a%c) if(b&1) w=1ll*w*a%c;
	return w%c;
};
auto C=[](int b,int a)->int{
	if(a>b) return 0;
	return mul(frc[b],mul(inf[a],inf[b-a]));
};
signed main(){
	File(mos);	
	n=read(),m=read();
	for(int i=1;i<=n;i++) sum=inc(sum,mul(read(),m)%mod)%mod;
	n*=m,frc[0]=1,inv[1]=1,frc[1]=1;
	for(int i=2;i<=n+1;i++) inv[i]=mul(mod-mod/i,inv[mod%i]),frc[i]=mul(frc[i-1],i);
	inf[n]=ksm(frc[n],mod-2,mod);
	for(int i=1;i<=n;i++) ans=inc(ans,mul(i,inv[i+1]));
	ans=mul(ans,mul(sum,mul(inf[n],frc[n-1]))); printf("%d\n",ans);
	exit(0);
}

B. 聚烷撑乙二醇

签到题.

B_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS{
	#define int long long
	#define lf long double
	#define pb push_back
	#define mp make_pair
	#define lb lower_bound
	#define ub upper_bound
	#define lbt(x) ((x)&(-(x)))
	#define Fill(x,y) memset(x,y,sizeof(x))
	#define Copy(x,y) memcpy(x,y,sizeof(x))
	#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
	auto read=[]()->int{
		int w=0; bool cit=1; char ch;
		while(!isdigit(ch=getchar())) if(ch=='-') cit=0;
		while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar();
		return cit?w:(-w);
	};
} using namespace BSS;

const int N=1e6+21;

lf ans,maxn;
lf le[N],ri[N];
int m,n;
signed main(){
	File(pag);
	n=read(); bool flag=1;
	for(int i=1;i<=n;i++){
		le[i]=read(),ri[i]=read(),flag&=(le[i]==ri[i]);
		maxn=max(maxn,le[i]);
	}
	if(flag) printf("%.5LF",maxn),exit(0);
	ans=(ri[n]-le[n])/2.0+le[n]; lf x,y,z;
	for(int i=n-1;i>=1;i--){
		if(ans>=ri[i]) continue;
		if(ans<=le[i]) { ans=(ri[i]-le[i])/2.0+le[i]; continue; }
		z=ri[i]-le[i],x=(ans-le[i])/z,y=1.0-x;
		ans=ans*x+((ri[i]-ans)/2.0+ans)*(1-x);
	}	
	printf("%.5LF\n",ans),exit(0);
}

C. 技术情报局

签到题.

C_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS{
	// #define int long long
	#define lf long double
	#define pb push_back
	#define mp make_pair
	#define lb lower_bound
	#define ub upper_bound
	#define lbt(x) ((x)&(-(x)))
	#define Fill(x,y) memset(x,y,sizeof(x))
	#define Copy(x,y) memcpy(x,y,sizeof(x))
	#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
	auto read=[]()->int{
		int w=0; bool cit=1; char ch;
		while(!isdigit(ch=getchar())) if(ch=='-') cit=0;
		while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar();
		return cit?w:(-w);
	};
} using namespace BSS;

namespace GenHelper {
	unsigned z1, z2, z3, z4, b;
	unsigned rand_() {
		b = ((z1 << 6) ^ z1) >> 13;
		z1 = ((z1 & 4294967294U) << 18) ^ b;
		b = ((z2 << 2) ^ z2) >> 27;
		z2 = ((z2 & 4294967288U) << 2) ^ b;
		b = ((z3 << 13) ^ z3) >> 21;
		z3 = ((z3 & 4294967280U) << 7) ^ b;
		b = ((z4 << 3) ^ z4) >> 12;
		z4 = ((z4 & 4294967168U) << 13) ^ b;
		return (z1 ^ z2 ^ z3 ^ z4);
	}
}
vector<int> get (int n, unsigned s, int l, int r) {
	vector<int> a;
	using namespace GenHelper;
	z1 = s;
	z2 = unsigned((~s) ^ 0x233333333U);
	z3 = unsigned(s ^ 0x1234598766U);
	z4 = (~s) + 51;
	for (int i = 1; i <= n; i ++) {
		int x = rand_() & 32767;
		int y = rand_() & 32767;
		a.push_back(l + (x * 32768 + y) % (r - l + 1));
	}
	return a;
}


#define LL long long 

const int N=1e7+21;

int ans,mod;
int n,tail;
int val[N],pre[N],suf[N],le[N],ri[N],stk[N],mul[N],lson[N],rson[N];
int cc[N][3];
vector<int> temp;
auto inc=[](int i,int j){ i+=j; return i>=mod ? i-mod : i ; };
void dfs(int u){
	cc[u][0]=cc[u][1]=val[u],cc[u][2]=1,mul[u]=val[u];
	if(lson[u]){
		dfs(lson[u]);
		mul[u]=1ll*mul[u]*mul[lson[u]]%mod;
		cc[u][0]=1ll*mul[lson[u]]*val[u]%mod;
	}
	if(rson[u]){
		dfs(rson[u]);
		mul[u]=1ll*mul[u]*mul[rson[u]]%mod;
		cc[u][1]=1ll*mul[rson[u]]*val[u]%mod;
		cc[u][2]=mul[rson[u]];
	}
}
signed main(){
	File(tio);
	n=read(); int s=read(),l=read(),r=read(); mod=read();
	temp=get(n,s,l,r); LL x,y,z,sum;
	for(int i=1;i<=n;i++){
		val[i]=inc(0,temp[i-1]),le[i]=i,ri[i]=i;
		pre[i]=inc(1ll*pre[i-1]*val[i]%mod,val[i])%mod;
		while(tail and val[x=stk[tail]]<=val[i]){
			le[i]=min(le[i],le[x]),ri[x]=max(ri[x],i-1);
			lson[i]=stk[tail--];
		}
		if(tail) rson[stk[tail]]=i; stk[++tail]=i;
	}
	while(tail) x=stk[tail--],ri[x]=n;
	for(int i=n;i>=1;i--) suf[i]=inc(1ll*suf[i+1]*val[i]%mod,val[i])%mod;
	dfs(x);
	for(int i=1;i<=n;i++){
		x=val[i],l=le[i],r=ri[i],sum=0;
		y=inc(pre[i],mod-1ll*pre[l-1]*cc[i][0]%mod);//l i
		z=inc(suf[i],mod-1ll*suf[r+1]*cc[i][1]%mod);// i r
		y=inc(y,mod-x),sum=inc(sum,inc(y,z))%mod;
		z=inc(suf[i+1],mod-1ll*suf[r+1]*cc[i][2]%mod);// i+1 r
		sum=inc(sum,1ll*y*z%mod)%mod,ans=inc(ans,1ll*sum*x%mod)%mod;
	}
	printf("%d\n",ans),exit(0);
}

D. 肯德基

签到题.

D_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS{
	#define int long long
	#define lf long double
	#define pb push_back
	#define mp make_pair
	#define lb lower_bound
	#define ub upper_bound
	#define lbt(x) ((x)&(-(x)))
	#define Fill(x,y) memset(x,y,sizeof(x))
	#define Copy(x,y) memcpy(x,y,sizeof(x))
	#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
	auto read=[]()->int{
		int w=0; bool cit=1; char ch;
		while(!isdigit(ch=getchar())) if(ch=='-') cit=0;
		while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar();
		return cit?w:(-w);
	};
} using namespace BSS;

#define ull unsigned long long 
const int N=1e7+21;

ull ans;
int n,m,cnt;
signed miu[N],vis[N],pri[N];
ull pre[N];
auto Sieve=[]()->void{
	miu[1]=1,pre[1]=1;
	for(int i=2;i<=1e7;i++){
		if(!vis[i]) miu[i]=-1,pri[++cnt]=i;
		for(int j=1;j<=cnt and i*pri[j]<=1e7;j++){
			vis[i*pri[j]]=1;
			if(i%pri[j]==0){ miu[i*pri[j]]=0; break; }
			miu[i*pri[j]]=-miu[i];
		}
		pre[i]=pre[i-1]+1ull*(i*i*miu[i]);
	}
};
auto calc=[](ull x)->ull{
	return (x&1) ? (x+1)/2ull*x : x/2ull*(x+1) ;
};
auto Work=[]()->void{
	n=read(),m=sqrt(n),ans=0;
	for(int l=1,r;l<=m;l=r+1){
		r=min(m,(int)sqrt(n/(n/(l*l))));
		ans+=(pre[r]-pre[l-1])*calc(n/(l*l));
	}
	printf("%llu\n",ans);
};
signed main(){
	File(kfc);
	Sieve();
	for(int Ts=read();Ts;Ts--) Work();
}
posted @ 2021-11-01 19:46  AaMuXiiiiii  阅读(37)  评论(1编辑  收藏  举报