其他分享
首页 > 其他分享> > 2022/8/17 总结

2022/8/17 总结

作者:互联网

A.P4343 [SHOI2015]自动刷题机

Solution

AC code
#include<bits/stdc++.h>
using namespace std;

inline int read(){
	int s=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		s=s*10+int(ch-'0');
		ch=getchar();
	}
	return s*f;
}

const int N=1e5+10;

#define ll long long

int L,k;
int x[N];
ll ans1=-1,ans2;

int check(ll n){
	int cnt=0;
	ll sum=0;
	for(int i=1;i<=L;++i){
		sum=max(0ll,sum+x[i]);
		if(sum>=n){
			++cnt;
			sum=0;
		}
	}
	return cnt;
}

void find_min(){
	ll l=1,r=1e14;
	while(l<=r){
		ll mid=(l+r)>>1;
		if(check(mid)>k)
			l=mid+1;
		else if(check(mid)==k){
			r=mid-1;
			ans1=mid;
		}
		else if(check(mid)<k)
			r=mid-1;
	}
	return ;
}

void find_max(){
	ll l=1,r=1e18;
	while(l<=r){
		ll mid=(l+r+1)>>1;
		if(check(mid)>k)
			l=mid+1;
		else if(check(mid)==k){
			ans2=mid;
			l=mid+1;
		}
		else if(check(mid)<k)
			r=mid-1;
	}
	return ;
}

int main(){
//	freopen("autoac.in","r",stdin);
//	freopen("autoac.out","w",stdout);
	L=read(),k=read();
	for(int i=1;i<=L;++i)
		x[i]=read();
	ans1=-1;
	find_min();
	find_max();
	if(ans1==-1) puts("-1");
	else printf("%lld %lld",ans1,ans2);
	return 0;
}

B.P2592 [ZJOI2008]生日聚会

C.P4340 [SHOI2016]随机序列

Solution

AC code
#include<bits/stdc++.h>
using namespace std;

inline int read(){
	int s=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		s=s*10+int(ch-'0');
		ch=getchar();
	}
	return s*f;
}

const int N=1e5+10;
const int mod=1e9+7;

#define ll long long

int n,Q;
ll mul[N];
ll fm[N];
ll x[N];

struct memr{
	int l,r;
	ll sum,tg;
}tr[N<<4];

ll ksm(ll x,int y){
	if(y<1) return 1;
	ll cnt=1,d=x;
	for(;y;y>>=1,(d*=d)%=mod)
		if(y&1)
			(cnt*=d)%=mod;
	return cnt;
}

void pushup(int p){
	(tr[p].sum=0ll+tr[p<<1].sum+tr[p<<1|1].sum)%=mod;
	return ;
}

void pushdown(int p){
	if(tr[p].tg!=1){
		(tr[p<<1].sum*=1ll*tr[p].tg)%=mod;
		(tr[p<<1|1].sum*=1ll*tr[p].tg)%=mod;
		(tr[p<<1].tg*=1ll*tr[p].tg)%=mod;
		(tr[p<<1|1].tg*=1ll*tr[p].tg)%=mod;
		tr[p].tg=1;
	}
	return ;
}

void build(int p,int l,int r){
	tr[p].l=l,tr[p].r=r;
	tr[p].tg=1;
	if(l==r){
		tr[p].sum=(mul[l]*x[l])%mod;
		return ;
	}
	int mid=(l+r)>>1;
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r);
	pushup(p);
	return ;
}

void change(int p,int l,int r,ll v){
	if(l<=tr[p].l && tr[p].r<=r){
		(tr[p].sum*=1ll*v)%=mod;
		(tr[p].tg*=1ll*v)%=mod;
		return ;
	}
	pushdown(p);
	int mid=(tr[p].l+tr[p].r)>>1;
	if(l<=mid) change(p<<1,l,r,v);
	if(mid<r) change(p<<1|1,l,r,v);
	pushup(p);
	return ;
}

int main(){
//	freopen("rand.in","r",stdin);
//	freopen("rand.out","w",stdout);
	n=read(),Q=read();
	mul[0]=1;
	int a;
	for(int i=1;i<=n;++i){
		a=read();
		(mul[i]=1ll*mul[i-1]*a)%=mod;
		(fm[i]=ksm(1ll*a,mod-2))%=mod;
		(x[i]=ksm(3,n-i-1)*(i!=n?2:1))%=mod;
	}
	build(1,1,n);
	int v;
	for(int i=1;i<=Q;++i){
		a=read(),v=read();
		change(1,a,n,fm[a]);
		change(1,a,n,1ll*v);
		fm[a]=ksm(1ll*v,mod-2);
		printf("%lld\n",tr[1].sum);
	}
	return 0;
}

标签:总结,ch,乘积,17,int,ll,mid,2022,check
来源: https://www.cnblogs.com/Star-LIcsAy/p/16596444.html