牛客网暑期ACM多校训练营day3
A dp
#include<iostream> #include<vector> using namespace std; int dp[37][37][37][37]; int n; int p[37],a[37],c[37],m[37],g[37]; int P,A,C,M; //int _n[36][36][37][37]; bool vis[37][37][37][37][37]; int main() { cin>>n; for(int i = 1;i<=n;i++) cin>>p[i]>>a[i]>>c[i]>>m[i]>>g[i]; cin>>P>>A>>C>>M; for(int i = 1;i<=n;i++){ for(int pp =P;pp>=p[i];pp--){ for(int aa = A;aa>=a[i];aa--){ for(int cc=C;cc>=c[i];cc--){ for(int mm = M;mm>=m[i];mm--){ // cout<<"::"<<pp<<" "<<aa<<" "<<cc<<" "<<mm<<endl; if(dp[pp][aa][cc][mm] > dp[pp-p[i]][aa-a[i]][cc-c[i]][mm-m[i]]+g[i]){ vis[i][pp][aa][cc][mm] = false; } else{ dp[pp][aa][cc][mm] = dp[pp-p[i]][aa-a[i]][cc-c[i]][mm-m[i]]+g[i]; vis[i][pp][aa][cc][mm] = true; } } } } } } //cout<<dp[P][A][C][M]<<endl; int pp = P,aa = A,cc = C,mm = M; vector<int>ans; for(int i = n;i>=1;i--) { if(vis[i][pp][aa][cc][mm] == true){ ans.push_back(i-1); pp-=p[i];aa-=a[i];cc-=c[i];mm-=m[i]; } } int n = ans.size(); cout<<n<<endl; for(int i=0;i<n;i++) cout<<ans[i]<<endl; }
C splay模板题
#include <bits/stdc++.h> const int MAXN=1e5+10; using namespace std; int pre[MAXN],ch[MAXN][2],size[MAXN],key[MAXN]; int cnt,root;int a[MAXN];int n; void newnode(int &x,int y,int vul){ x=++cnt; pre[x]=y;ch[x][0]=ch[x][1]=0;size[x]=1;key[x]=vul; } void up(int x){size[x]=size[ch[x][0]]+size[ch[x][1]]+1;} void Treavel(int x) { if(x) { Treavel(ch[x][0]); printf("结点%2d:左儿子 %2d 右儿子 %2d 父结点 %2d size=%2d,key=%2d\n",x,ch[x][0],ch[x][1],pre[x],size[x],key[x]); Treavel(ch[x][1]); } } void debug(int rp) { printf("root:%d\n",rp); Treavel(rp); } void rotate(int x,int kind){ int y=pre[x]; ch[y][!kind]=ch[x][kind];pre[ch[x][kind]]=y; if(pre[y])ch[pre[y]][ch[pre[y]][1]==y]=x; pre[x]=pre[y];ch[x][kind]=y;pre[y]=x; up(y);up(x); } void splay(int x,int goal){ while(pre[x]!=goal){ if(pre[pre[x]]==goal)rotate(x,ch[pre[x]][0]==x); else{ int y=pre[x];int kind=ch[pre[y]][0]==y; if(ch[y][kind]==x)rotate(x,!kind),rotate(x,kind); else rotate(y,kind),rotate(x,kind); } } if(goal==0)root=x; up(x); } int find1(int x,int sz){ if(sz==size[ch[x][0]]+1)return x; else if(sz<=size[ch[x][0]])return find1(ch[x][0],sz); else return find1(ch[x][1],sz-size[ch[x][0]]-1); } void operator1(int k,int l){ splay(find1(root,k),0); splay(find1(root,l+k+1),root); int t1=ch[ch[root][1]][0]; ch[ch[root][1]][0]=0;up(ch[root][1]);up(root); pre[t1]=0; splay(find1(root,1),0); splay(find1(root,2),root); pre[t1]=ch[root][1]; ch[ch[root][1]][0]=t1;up(ch[root][1]);up(root); // debug(root); } void built(int &x,int l,int r,int fa){ if(l>r)return ; int mid=(l+r)>>1; // cout<<l<<" "<<r<<endl; newnode(x,fa,mid); built(ch[x][0],l,mid-1,x); built(ch[x][1],mid+1,r,x); up(x); } void inte(){ newnode(root,0,-1); newnode(ch[root][1],root,-1); built(ch[ch[root][1]][0],1,n,ch[root][1]); up(ch[root][1]);up(root); // debug(root); } void dfs(int x){ if(!x)return ; dfs(ch[x][0]); printf("%d ",key[x]); dfs(ch[x][1]); } int q; int main(){ scanf("%d%d",&n,&q); //for(int i=1;i<=n;i++)scanf("%d",&a[i]); inte();int k,l; for(int i=1;i<=q;i++){ scanf("%d%d",&k,&l); operator1(k,l); } splay(1,0);splay(2,root); dfs(ch[ch[root][1]][0]); }
Dhttps://www.cnblogs.com/greenty1208/p/9379440.html
贴队友博客
E 双hash
#include<bits/stdc++.h> #define inc(i,l,r) for(int i=l;i<=r;i++) #define dec(i,l,r) for(int i=l;i>=r;i--) #define link(x) for(edge*j=h[x];j;j=j->next) #define succ(x) (1LL<<(x)) #define sqr(x) ((x)*(x)) #define mem(a) memset(a,0,sizeof(a)) #define lowbit(x) (x&(-x)) #define ll long long #define moid (x+y>>1) #define eps 1e-8 #define MAXN 1000005 using namespace std; ll read(){ ll x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); return x*f; } int n,tot; typedef struct tmp{ ll t1,t2;int t3; friend bool operator<(tmp aa,tmp bb){ if(aa.t1!=bb.t1)return aa.t1<bb.t1; if(aa.t2!=bb.t2)return aa.t2<bb.t2; return aa.t3<bb.t3; } }tmp; tmp c[MAXN]; //pair<int,ll>c[MAXN]; ll x,_t,_t1,y; const ll t1=21841; const ll inf1=290182597; const ll t=1007; const ll inf=1e9+7; char s[2*MAXN]; vector<int>vec[MAXN]; typedef struct node{ int t1,t2,id; friend bool operator<(node aa,node bb){ if(aa.t1==bb.t1)return aa.t2<bb.t2; return aa.t1<bb.t1; } }node; node d[MAXN]; int main(){ scanf("%s",s+1); n=strlen(s+1); inc(i,1,n)s[i+n]=s[i]; x=0; inc(i,1,n){ x=(x*t+s[i])%inf; y=(y*t1+sqr(s[i]))%inf1; } c[++tot]=(tmp){x,y,0};_t=_t1=1; inc(i,1,n-1)_t=_t*t%inf,_t1=_t1*t1%inf1; inc(i,n+1,2*n-1){ x-=_t*s[i]%inf;x%=inf;x=(x+inf)%inf; y-=_t1*sqr(s[i])%inf1;y%=inf1;y=(y+inf1)%inf1; x=(x*t+s[i])%inf; y=(y*t1+sqr(s[i]))%inf1; c[++tot]=(tmp){x,y,i-n}; } sort(c+1,c+1+tot);int cnt=0; ll last=-1,last1=-1; inc(i,1,n){ if(c[i].t1==last&&last1==c[i].t2)vec[cnt].push_back(c[i].t3); else vec[++cnt].push_back(c[i].t3); last=c[i].t1;last1=c[i].t2; } //or(int i=1;i<=tot;i++)cout<<c[i].t1<<" "<<c[i].t2<<endl; for(int i=1;i<=cnt;i++)d[i].t1=vec[i].size(),d[i].t2=vec[i][0],d[i].id=i; sort(d+1,d+cnt+1); printf("%d\n",cnt); for(int i=1;i<=cnt;i++){ printf("%d",vec[d[i].id].size()); for(int j=0;j<vec[d[i].id].size();j++)printf(" %d",vec[d[i].id][j]); printf("\n"); } return 0; }
F math&数据结构 另开随笔推到过程
#include <bits/stdc++.h> #define ll long long const int MAXN=1e5+10; const ll mod=1e9+7; using namespace std; ll d[MAXN<<2][16];int a[MAXN]; void up(int rt){ for(int i=0;i<=15;i++)d[rt][i]=0; for(int i=0;i<=15;i++){ for(int j=0;j<=15;j++){ if(i==0&&j==0)d[rt][0]+=1ll*d[rt<<1][i]*d[rt<<1|1][j]%mod,d[rt][0]%=mod; else{ int t1=(i+j)%15; if(!t1)t1=15; d[rt][t1]+=1ll*d[rt<<1][i]*d[rt<<1|1][j]%mod;d[rt][t1]%=mod; } } } for(int i=0;i<=15;i++)d[rt][i]+=(d[rt<<1][i]+d[rt<<1|1][i])%mod,d[rt][i]%=mod; } //void clear() void built(int rt,int l,int r){ if(l==r){d[rt][a[l]]=1;return ;} int mid=(l+r)>>1; built(rt<<1,l,mid); built(rt<<1|1,mid+1,r); up(rt); } void update(int rt,int l,int r,int t,int vul){ if(l==r){d[rt][a[l]]=0;d[rt][vul]=1;return ;} int mid=(l+r)>>1; if(t<=mid)update(rt<<1,l,mid,t,vul); else update(rt<<1|1,mid+1,r,t,vul); up(rt); } ll ans[16],ans1[16];bool flag; void merge(int x){ // cout<<"====="<<endl; // for(int i=0;i<=15;i++)cout<<d[x][i]<<" "; // cout<<endl; for(int i=0;i<=15;i++)ans1[i]=0; for(int i=0;i<=15;i++){ for(int j=0;j<=15;j++){ if(i==0&&j==0)ans1[0]+=1ll*ans[i]*d[x][j]%mod,ans1[0]%=mod; else{ int t1=(i+j)%15; if(!t1)t1=15; ans1[t1]+=1ll*ans[i]*d[x][j]%mod;ans1[t1]%=mod; } } } for(int i=0;i<=15;i++)ans1[i]+=d[x][i]+ans[i],ans1[i]%=mod; for(int i=0;i<=15;i++)ans[i]=ans1[i]; } void querty(int rt,int l,int r,int ql,int qr){ if(ql<=l&&r<=qr){ if(!flag){ for(int i=0;i<=15;i++)ans[i]=d[rt][i]; flag=1;return ; } else merge(rt); return ; } int mid=(l+r)>>1; if(ql<=mid)querty(rt<<1,l,mid,ql,qr); if(qr>mid)querty(rt<<1|1,mid+1,r,ql,qr); } ll sum[16]; char str[MAXN],s[111]; int main(){ sum[0]=1; for(int i=1;i<=15;i++)sum[i]=sum[i-1]*1021%mod; int n,q;scanf("%d%d",&n,&q); char ch; scanf("%s",str+1); for(int i=1;i<=n;i++){//scanf(" %c",&ch); if(str[i]>='0'&&str[i]<='9')a[i]=(str[i]-'0'); else a[i]=(str[i]-'A')+10; } built(1,1,n); int op,l,r; for(int i=1;i<=q;i++){ scanf("%d",&op); if(op==1){scanf("%d%s",&l,s); if(s[0]>='0'&&s[0]<='9')r=(s[0]-'0'); else r=(s[0]-'A')+10; update(1,1,n,l,r); a[l]=r; } else{ flag=0; for(int i=0;i<=15;i++)ans[i]=0; scanf("%d%d",&l,&r); querty(1,1,n,l,r); ll ans2=0; for(int i=0;i<=15;i++)ans2+=(1ll*sum[i]*ans[i])%mod,ans2%=mod; printf("%lld\n",ans2%mod); } } return 0; }
H 签到
https://blog.csdn.net/qkoqhh/article/details/81222366
#include<bits/stdc++.h> #define inc(i,l,r) for(int i=l;i<=r;i++) #define dec(i,l,r) for(int i=l;i>=r;i--) #define link(x) for(edge*j=h[x];j;j=j->next) #define inf 1e9 #define succ(x) (1LL<<(x)) #define sqr(x) ((x)*(x)) #define mem(a) memset(a,0,sizeof(a)) #define lowbit(x) (x&(-x)) #define ll long long #define moid (x+y>>1) #define eps 1e-8 #define NM 10000005 ll read(){ ll x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); return x*f; } int n,prime[NM],m,tot; bool v[NM]; ll a[NM],s; int main(){ n=read(); tot=0; inc(i,2,n){ if(!v[i])prime[++tot]=i; inc(j,1,tot){ if(i*prime[j]>n)break; v[i*prime[j]]=true; if(i%prime[j]==0)break; } } inc(i,2,n)a[i]=a[i-1]+!v[i]; inc(i,1,n)s+=a[n/i]*(a[n/i]-1); return 0*printf("%lld\n",s); }
I 贴队友博客
https://blog.csdn.net/qkoqhh/article/details/81228950
J队友博客