2017-10-04-afternoon
注意完全平方数统计时的特判
1 #include <cstdio> 2 3 inline void read(int &x) 4 { 5 x=0; register char ch=getchar(); 6 for(; ch>'9'||ch<'0'; ) ch=getchar(); 7 for(; ch>='0'&&ch<='9'; ch=getchar()) x=x*10+ch-'0'; 8 } 9 const int N(40005); 10 int n,cnt[N],ans; 11 12 inline void Update(int x) 13 { 14 int i; 15 for(i=1; i*i<x; ++i) 16 if(x%i==0) cnt[i]++,cnt[x/i]++; 17 if(i*i==x) cnt[i]++; 18 } 19 20 int Presist() 21 { 22 freopen("a.in","r",stdin); 23 freopen("a.out","w",stdout); 24 25 read(n); 26 for(int op,x; n--; ) 27 { 28 read(op),read(x); 29 if(op==1) Update(x); 30 else ans^=cnt[x]; 31 } 32 printf("%d\n",ans); 33 return 0; 34 } 35 36 int Aptal=Presist(); 37 int main(int argc,char**argv){;}
1 #include <cstring> 2 #include <cstdio> 3 4 #define LL long long 5 inline void read(int &x) 6 { 7 x=0; register char ch=getchar(); 8 for(; ch>'9'||ch<'0'; ) ch=getchar(); 9 for(; ch>='0'&&ch<='9'; ch=getchar()) x=x*10+ch-'0'; 10 } 11 const int N(3e5+5); 12 13 int cnt[2][N],val[N],dad[N]; 14 int sumedge,head[N]; 15 struct Edge { 16 int v,next,w; 17 Edge(int v=0,int next=0,int w=0):v(v),next(next),w(w){} 18 }edge[N<<1]; 19 inline void ins(int u,int v,int w) 20 { 21 cnt[0][u]++; cnt[0][v]++; 22 edge[++sumedge]=Edge(v,head[u],w); head[u]=sumedge; 23 edge[++sumedge]=Edge(u,head[v],w); head[v]=sumedge; 24 } 25 26 bool vis[N]; 27 long long ans; 28 29 inline void Add(int u) 30 { 31 for(; dad[u]; u=dad[u]) cnt[1][dad[u]]++; 32 } 33 void DFS(int u,int fa,int pre) 34 { 35 for(int v,i=head[u]; i; i=edge[i].next) 36 { 37 v=edge[i].v; 38 if(vis[v]||fa==v||edge[i].w==pre) continue; 39 cnt[1][v]++, dad[v]=u; 40 DFS(v,u,edge[i].w); Add(v); dad[v]=0; 41 } 42 } 43 44 int Presist() 45 { 46 freopen("b.in","r",stdin); 47 freopen("b.out","w",stdout); 48 int n; read(n); 49 for(int i=1; i<=n; ++i) read(val[i]); 50 for(int u,v,w,i=1; i<n; ++i) 51 read(u),read(v),read(w),ins(u,v,w); 52 for(int i=1; i<=n; ++i) 53 if(cnt[0][i]==1) vis[i]=1,DFS(i,0,0); 54 for(int i=1; i<=n; ++i) 55 if(!vis[i]) vis[i]=1,DFS(i,0,0); 56 for(int i=1; i<=n; ++i) 57 ans+=1ll*cnt[1][i]*val[i]; 58 printf("%I64d\n",ans); 59 return 0; 60 } 61 62 int Aptal=Presist(); 63 int main(int argc,char**argv){;}
1 /* 2 呃呃呃 3 */
——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。