B Title:
Title: seeking
Train of Thought: Original FormAnd then high-precision calculations can be done.
#include <bits/stdc++.h> using namespace std; //n*(n+1)*(n+2)/6+(n+1)*(n+1)/4 struct node{ int a[11000],len; node(){ memset(a,0,sizeof(a)); len=0; } node operator = (node b){ memcpy(a,b.a,sizeof(a)); len=b.len; return *this; } node operator + (int b){ node c=*this;c.a[1]+=b;int x=0; for(int i=1;i<=c.len;i++){ if (c.a[i]>9){ c.a[i+1]+=c.a[i]/10; c.a[i]%=10; } else break; } // if (c.a[c.len]>9){ // c.a[c.len+1]=c.a[c.len]/10; // c.a[c.len]%=10;c.len++; // } if (c.a[c.len+1]) c.len++; return c; } node operator + (node b){ node c;c.len=max(len,b.len); register int jinwei=0; for(int i=1;i<=c.len;i++){ c.a[i]=a[i]+b.a[i]+jinwei; jinwei=c.a[i]/10;c.a[i]%=10; } if (jinwei) c.a[++c.len]=jinwei; return c; } node operator * (node b){ node c; for(int i=1;i<=len;i++){ register int x=0,j; for(j=1;j<=b.len;j++){ c.a[i+j-1]+=a[i]*b.a[j]+x; x=c.a[i+j-1]/10; c.a[i+j-1]%=10; } if (x) c.a[i+b.len]=x; } c.len=len+b.len+10; while (c.len>1&&c.a[c.len]==0) c.len--; return c; } node operator / (int b){ node c;int p=0,i; for(int i=len;i;i--){ p=p*10+a[i]; c.a[i]=p/b; p%=b; } c.len=len; while (c.len>1&&c.a[c.len]==0) c.len--; return c; } void read(){ string s;cin>>s;len=s.size(); for(int i=0;i<len;i++) a[len-i]=s[i]-'0'; } void print(){ // printf("len=%d\n",len); for(int i=len;i;i--) printf("%d",a[i]); printf("\n"); } }n,ans; int main(){ n.read();//n.print(); ans=n*(n+1)*(n+2)/6+(n+1)*(n+1)/4; ans.print(); return 0; }
D Title:
Topic: now give you a directed graph with n points and m edges. For each point v, we remember A(v) to denote the largest number of points that can be reached from v. You are required to calculate the A(i) values of all points within the linear complexity time.
Ideas: Reverse edge building, memory search can be
#include <bits/stdc++.h> using namespace std; const int N=1e5+1e3; int n,m,x,y,i,a[N]; vector<int> v[N]; void dfs(int x,int k){ // if (v[x].size()==0) // return a[x]=x; if (a[x]!=-1) return;a[x]=k; for(int i=0;i<v[x].size();i++){ register int to=v[x][i]; // if (!flag[to]) continue; // flag[to]=false; dfs(to,k); // flag[to]=true; } // a[x]=max(a[x],x); // return a[x]; } int main(){ scanf("%d%d",&n,&m); for(i=1;i<=m;i++){ scanf("%d%d",&x,&y); v[y].push_back(x); // v[y].push_back(x); } memset(a,-1,sizeof(a)); for(i=n;i;i--) dfs(i,i); for(i=1;i<=n;i++) printf("%d ",a[i]); return 0; }
In addition, Question C refers to Luogu, but it is not yet AC.