$$ \newcommand{\seq}[2]{{#1}_{1},{#1}_{2},\cdots,{#1}_{#2}} \newcommand{\num}[1]{1,2,\cdots,#1} \newcommand{\stra}[2]{\begin{bmatrix}#1 \\ #2\end{bmatrix}} \newcommand{\strb}[2]{\begin{Bmatrix}#1 \\ #2\end{Bmatrix}} \newcommand{\dw}[1]{\underline{#1}} \newcommand{\up}[1]{\overline{#1}} $$

contest0 20180804

A

Code

#include<bits/stdc++.h>
using namespace std;
const int maxc=1003,mod=1000000007;
int n,m,c,a[maxc],b[maxc],dp[maxc][maxc];
int Plus(int x,int y){return (x+=y)>=mod?x-mod:x;}
void PlusEqual(int &x,int y){if((x+=y)>=mod)x-=mod;}
int mul(long long x,int y){return x*y%mod;}
int main(){
	scanf("%d%d%d",&n,&m,&c);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		a[x]++;
	}
	for(int i=1;i<=m;i++){
		int x;
		scanf("%d",&x);
		b[x]++;
	}
	for(int i=c;i>=0;i--){
		a[i]=mul(a[i],b[i]);
		dp[i][0]=Plus(dp[i+1][0],a[i]);
	}
	for(int i=c;i>=0;i--){
		for(int j=c;j>=1;j--){
			dp[i][j]=Plus(mul(dp[i+1][j-1],a[i]),dp[i+1][j]);
		}
	}
	for(int i=1;i<=c;i++){
		printf("%d ",dp[1][i]);
	}
	return 0;
}

B

Code

#include<bits/stdc++.h>
using namespace std;
const int maxn=100003,mod=1000000007;
int n,Q,q[maxn][3],t[maxn],TT[maxn];
int Plus(int x,int y){return (x+=y)>=mod?x-mod:x;}
int Minus(int x,int y){return Plus(x,mod-y);}
void PlusEqual(int &x,int y){if((x+=y)>=mod)x-=mod;}
int mul(long long x,int y){return x*y%mod;}
void add(int pos,int k){while(pos<=Q)PlusEqual(t[pos],k),pos+=pos&-pos;}
int query(int pos){int ret=0;while(pos)PlusEqual(ret,t[pos]),pos-=pos&-pos;return ret;}
void ADD(int pos,int k){while(pos<=n)PlusEqual(TT[pos],k),pos+=pos&-pos;}
int QUERY(int pos){int ret=0;while(pos)PlusEqual(ret,TT[pos]),pos-=pos&-pos;return ret;}
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&n,&Q);
		memset(t,0,sizeof(t));
		memset(TT,0,sizeof(TT));
		for(int i=1;i<=Q;i++){
			for(int j=0;j<=2;j++)scanf("%d",&q[i][j]);
			add(i,1),add(i+1,-1);
		}
		for(int i=Q;i>=1;i--){
			if(q[i][0]==2){
				int tmp=query(i);
				add(q[i][1],tmp),add(q[i][2]+1,Minus(0,tmp));
			}
		}
		for(int i=1;i<=Q;i++){
			if(q[i][0]==1){
				int tmp=query(i);
				ADD(q[i][1],tmp),ADD(q[i][2]+1,Minus(0,tmp));
			}
		}
		for(int i=1;i<=n;i++){
			printf("%d%c",QUERY(i),i==n?'\n':' ');
		}
	}
	return 0;
}

C

Code

#include<bits/stdc++.h>
using namespace std;
const int maxn=200003;
int t[maxn][26],cnt,Q,TOT;
bool en[maxn];
char mo[maxn][2];
string s[maxn],ANS[maxn];
void insert(const string &str){
	int p=1;
	for(int i=0;i<int(str.size());i++){
		en[p]|=1;
		if(!t[p][str[i]-'a'])t[p][str[i]-'a']=++cnt;
		p=t[p][str[i]-'a'];
	}
	en[p]|=1;
}
bool query(const string &str){
	int p=1;
	TOT++;
	for(int i=0;i<int(str.size());i++){
		ANS[TOT]+=str[i];
		if(!t[p][str[i]-'a']||!en[t[p][str[i]-'a']])return 1;
		p=t[p][str[i]-'a'];
	}
	return 0;
}
int main(){
	cnt=1;
	cin>>Q;
	for(int i=1;i<=Q;i++){
		cin>>mo[i]>>s[i];
		if(mo[i][0]=='+'){
			insert(s[i]);
		}
	}
	for(int i=1;i<=Q;i++){
		if(mo[i][0]=='-'){
			if(!query(s[i])){
				cout<<-1<<endl;
				return 0;
			}
		}
	}
	sort(ANS+1,ANS+TOT+1);
	TOT=unique(ANS+1,ANS+TOT+1)-ANS-1;
	cout<<TOT<<endl;
	for(int i=1;i<=TOT;i++)cout<<ANS[i]<<endl;
	return 0;
}

D

Code

#include<bits/stdc++.h>
using namespace std;
const int maxn=1000003;
int n,k,a[maxn],cnt;
char s[maxn];
bool check(int x){
	int tot=0;
	for(int i=1;i<=cnt;i++){
		tot+=a[i]/(x+1);
		if(tot>k)return 0;
	}
	return 1;
}
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int l=2,r=1,mid,ans=-1;
		cnt=0;
		scanf("%d%d%s",&n,&k,s+1);
		for(int i=1;i<=n;i++)a[i]=0;
		for(int i=1,j;i<=n;i=j){
			for(j=i;j<=n&&s[j]==s[i];j++);
			a[++cnt]=j-i;
			r=max(r,a[cnt]);
		}
		int x=0;
		for(int i=1;i<=n;i++){
			if(s[i]==(i&1)+'0')x++;
		}
		if(x<=k||n-x<=k){
			puts("1");
		}
		else{
			while(l<=r){
				mid=(l+r)>>1;
				if(check(mid))ans=mid,r=mid-1;
				else l=mid+1;
			}
			printf("%d\n",ans);
		}
	}
	return 0;
}

E

Code

\(a/b\%c = a\%(b*c) / b\)

证明: 设 a / b = k * c + r, 那么a = k * b * c + b * r, 因此a - k * b * c = b * r
左边模bc之后等价于 a % (b * c) = b * r,因此取模bc之后的值仍然能被b整除

#include<bits/stdc++.h>
using namespace std;
int mod;
int Sum(long long i){
	return i%mod*(i+1)%mod*(2*i+1)%mod*((3*i%mod*i%mod+3*i-1+mod)%mod)%mod/30;
}
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		long long n,tmp1,tmp2,ans=0;
		scanf("%lld%d",&n,&mod);
		for(long long i=1,j;i<=n;i=j+1){
			j=n/(n/i);
			mod*=30;
			tmp1=Sum(i-1);
			tmp2=Sum(j);
			mod/=30;
			ans=(ans+(tmp2-tmp1+mod)%mod*(n/i)%mod)%mod;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
posted @ 2019-07-24 11:43  chc_1234567890  阅读(122)  评论(0编辑  收藏  举报