标签:sizeof getchar pac dfs long lap end 重写 code
毒瘤卡常啊我勒个去
A 题被卡常我要骂人了
C 题写了一个常数大的做法,被卡到怀疑人生(后来重写才 AC 的mdzz)。
还好 B 和 D 比较善良
题解不想写了
直接放代码QAQ
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=100005; LL read(){ LL x=0,f=1; char ch=getchar(); while (!isdigit(ch)&&ch!=‘-‘) ch=getchar(); if (ch==‘-‘) f=-1,ch=getchar(); while (isdigit(ch)) x=(x<<1)+(x<<3)+ch-48,ch=getchar(); return x*f; } int n,A[N],fa[N]; int a1[N],b1[N],a2[N],b2[N]; int main(){ int T=read(); while (T--){ n=read(); memset(a1,0,sizeof a1); memset(a2,0,sizeof a2); memset(b1,0,sizeof b1); memset(b2,0,sizeof b2); for (int i=2;i<=n;i++) fa[i]=read(); for (int i=1;i<=n;i++) A[i]=read(); for (int i=2;i<=n;i++){ int v=A[i],f=fa[i]; if (v>=a1[f]) a2[f]=a1[f],a1[f]=v; else a2[f]=max(a2[f],v); if (v<=b1[f]) b2[f]=b1[f],b1[f]=v; else b2[f]=min(b2[f],v); } LL Max=0,Min=0; for (int i=1;i<=n;i++){ Max+=a1[i]; Min+=b1[i]; } LL ans1=Max,ans2=Min; for (int i=1;i<=n;i++){ ans1=max(ans1,Max+a2[i]); ans2=min(ans2,Min+b2[i]); } printf("%I64d %I64d\n",ans1+max(A[1],0),ans2+min(A[1],0)); } return 0; }
#pragma GCC optimize("Ofast") #pragma GCC optimize("inline") #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=105,V=10005,mod=1e9+7; int T,n,L[N],R[N],inv[N]; int Pow(int x,int y){ int ans=1; for (;y;y>>=1,x=1LL*x*x%mod) if (y&1) ans=1LL*ans*x%mod; return ans; } int calc(int x){ return x*(x+1)/2; } int main(){ scanf("%d",&T); while (T--){ scanf("%d",&n); int MaxL=0,MaxR=0; for (int i=1;i<=n;i++){ scanf("%d%d",&L[i],&R[i]); MaxL=max(MaxL,L[i]); MaxR=max(MaxR,R[i]); inv[i]=Pow(R[i]-L[i]+1,mod-2); } int ans=0; for (int i=MaxL;i<=MaxR;i++){ int v0=1,v1=0; for (int j=1;j<=n;j++){ if (R[j]<i){ v0=1LL*v0*(calc(i-L[j]+1)-calc(i-R[j]))%mod; v1=1LL*v1*(calc(i-L[j]+1)-calc(i-R[j]))%mod; } else { v1=(1LL*v1*calc(i-L[j]+1)%mod+1LL*v0%mod)%mod; v0=1LL*v0*(calc(i-L[j]+1)-1)%mod; } v1=1LL*v1*inv[j]%mod; v0=1LL*v0*inv[j]%mod; } ans=(ans+v1)%mod; // printf("%d %d\n",v0,v1); } printf("%d\n",ans); } return 0; }
#pragma GCC optimize("Ofast") #pragma GCC optimize("inline") #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=100005,mod=1e9+7; int read(){ int x=0; char ch=getchar(); while (!isdigit(ch)) ch=getchar(); while (isdigit(ch)) x=(x<<1)+(x<<3)+ch-48,ch=getchar(); return x; } struct Gragh{ static const int M=N*2; int cnt,y[M],nxt[M],fst[N]; void add(int a,int b){ y[++cnt]=b,nxt[cnt]=fst[a],fst[a]=cnt; } }g; int n,m,v[N],fa[N],id[N],p[N]; vector <int> vs[N]; int getf(int x){ return fa[x]==x?x:fa[x]=getf(fa[x]); } bool cmp(int a,int b){ return v[a]<v[b]; } int main(){ int T=read(); while (T--){ n=read(),m=read(); for (int i=1;i<=n;i++) v[i]=read(),id[i]=i; sort(id+1,id+n+1,cmp); for (int i=1;i<=n;i++) p[id[i]]=i,fa[i]=i; g.cnt=0; memset(g.fst,0,sizeof(int)*(n+1)); for (register int i=1;i<=m;i++){ int a=read(),b=read(); fa[getf(a)]=getf(b); } for (int i=1;i<=n;i++) vs[i].clear(); for (int i=1;i<=n;i++) vs[getf(id[i])].push_back(v[id[i]]); int ans=0; for (int i=1;i<=n;i++){ if (vs[i].size()<1) continue; for (int d=0;d<30;d++){ int cnt=0; for (vector <int> :: iterator p=vs[i].begin(); p!=vs[i].end();p++){ if (!(((*p)>>d)&1)) continue; ans=((1LL<<d)*cnt%mod*(*p)+ans)%mod; cnt++; } } } printf("%d\n",ans); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=1005,mod=1e9+7; LL read(){ LL x=0; char ch=getchar(); while (!isdigit(ch)) ch=getchar(); while (isdigit(ch)) x=(x<<1)+(x<<3)+ch-48,ch=getchar(); return x; } struct Pos{ int p[5]; }s[N*6]; int n,k,cnt,p[5],in[N*6]; vector <int> v[5][N],e[N*6]; bool check(Pos a,Pos b){ for (int i=0;i<k;i++) if (a.p[i]>=b.p[i]) return 0; return 1; } void dfs(int val,int d){ if (d>=k){ cnt++; for (int i=0;i<k;i++) s[cnt].p[i]=p[i]; return; } for (int i=0;i<v[d][val].size();i++){ p[d]=v[d][val][i]; dfs(val,d+1); } } int q[N*6],head,tail; int dp[N*6]; int main(){ int T=read(); while (T--){ k=read(),n=read(); for (int i=0;i<k;i++) for (int j=1;j<=n;j++) v[i][j].clear(); for (int i=0;i<k;i++) for (int j=1;j<=n;j++) v[i][read()].push_back(j); cnt=0; for (int i=1;i<=n;i++) dfs(i,0); for (int i=1;i<=cnt;i++) e[i].clear(); memset(in,0,sizeof in); for (int i=1;i<=cnt;i++) for (int j=1;j<=cnt;j++) if (check(s[i],s[j])) e[i].push_back(j),in[j]++; head=tail=0; for (int i=1;i<=cnt;i++) if (!in[i]) q[++tail]=i; for (int i=1;i<=cnt;i++) dp[i]=1; int ans=0; while (head<tail){ int x=q[++head]; ans=(ans+dp[x])%mod; for (int i=0;i<e[x].size();i++){ int y=e[x][i]; dp[y]=(dp[y]+dp[x])%mod; in[y]--; if (!in[y]) q[++tail]=y; } } printf("%d\n",ans); } return 0; }
标签:sizeof getchar pac dfs long lap end 重写 code
原文地址:https://www.cnblogs.com/zhouzhendong/p/Baidu-Star-2018-Rematch.html