結果
問題 | No.1790 Subtree Deletion |
ユーザー | fgwiebfaoish |
提出日時 | 2021-12-19 02:11:43 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 9,548 bytes |
コンパイル時間 | 2,960 ms |
コンパイル使用メモリ | 112,640 KB |
実行使用メモリ | 55,420 KB |
最終ジャッジ日時 | 2024-09-15 14:22:57 |
合計ジャッジ時間 | 10,208 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
17,792 KB |
testcase_01 | AC | 28 ms
17,920 KB |
testcase_02 | AC | 28 ms
18,176 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 115 ms
21,944 KB |
testcase_09 | AC | 579 ms
55,420 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; static class Program{ const int mod=(int)1e9+7; static List<int>[] li; static void Main(){ Sc sc=new Sc(); var s=sc.Ia; int n=s[0],m=n-1; li=new List<int>[n+1]; var h=new long[m][]; var b=new bool[n+1]; for(int i=1;i<=n;i++){li[i]=new List<int>();} for(int i=0;i<m;i++){ h[i]=sc.La; li[h[i][0]].Add((int)h[i][1]); li[h[i][1]].Add((int)h[i][0]); } var et=new Et(li,1); Lst st=new Lst(n+1); var g=new long[n+1]; var d=new long[n+1]; var r=new int[n+1]; for(int i = 0;i<m;i++) { int e=(int)(et.fa[h[i][0]]<et.fa[h[i][1]]?h[i][0]:h[i][1]); int f=(int)(et.fa[h[i][0]]>et.fa[h[i][1]]?h[i][0]:h[i][1]); g[e]^=h[i][2]; d[f]=h[i][2]; r[f]=e; } for(int i = 1;i<=n;i++) {st.Add(et.ixl2[i],et.ixl2[i],g[i]);} var q=sc.I; StringBuilder sb=new StringBuilder(); for(int i = 0;i<q;i++) { var e=sc.Ia; if(e[0]==1){ if(b[e[1]]){continue;} Fu(e[1]); st.Add(et.ixl2[r[e[1]]],et.ixl2[r[e[1]]],st.Get(et.ixl2[e[1]],et.ixr2[e[1]]).d1^d[e[1]]); void Fu(int a) { b[a]=true; for(int j = 0;j<li[a].Count;j++) { if(et.fa[li[a][j]]>et.fa[a]&&!b[et.fa[li[a][j]]]){Fu(li[a][j]);} } } } else{sb.Append((b[e[1]]?0:st.Get(et.ixl2[e[1]],et.ixr2[e[1]]).d1)+"\n");} } Console.Write(sb); } } public class Lst{ public struct Dt{ public long d1,lz1; public Dt(bool b){d1=0;lz1=0;} public Dt(long d1){ this.d1=d1; lz1=0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dt Um(Dt a,long n1,int h){ a.d1^=n1; return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dt Lm(Dt a,long n1){ a.lz1^=n1; return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dt Cm(Dt l,Dt r){ var a=new Dt(true); a.d1=l.d1^r.d1; return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dt Cl(Dt a){ a.lz1=0; return a; } public override string ToString(){ var me=GetType().GetFields(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance); var st=""; foreach (MemberInfo e in me){st+=e.Name+":"+GetType().GetField(e.Name).GetValue(this)+" ";} return st; } } const int mod=(int)1e9+7; private Dt[] dat; private int[] ha; private bool[] bo; private int n,m=1,cnt; private readonly Dt ie=new Dt(true); public Lst(int n){ this.n=n; while(m<n){m<<=1;} cnt=m+n; dat=new Dt[cnt]; bo=new bool[cnt]; ha=new int[cnt]; for(int i = 0;i<cnt;i++) {dat[i]=ie;} for(int i = cnt-n;i<cnt;i++) { ha[i]=1; ha[i>>1]++; } for(int i = cnt-n-1;i>1;i--) {ha[i>>1]+=ha[i];} } public Lst(int[] a){ n=a.Length; while(m<n){m<<=1;} cnt=m+n; dat=new Dt[cnt]; bo=new bool[cnt]; ha=new int[cnt]; for(int i = cnt-n;i<cnt;i++) { dat[i]=new Dt(a[i-cnt+n]); ha[i]=1; } for(int i = cnt-n-1;i>0;i--) { if(i<<1<cnt){ if((i<<1)+1<cnt){ dat[i]=Dt.Cm(dat[i<<1],dat[(i<<1)+1]); ha[i]=ha[i<<1]+ha[(i<<1)+1]; } else{ dat[i]=dat[i<<1]; ha[i]=ha[i<<1]; } } else{dat[i]=ie;} } } public Dt Get(int a,int b){return Fge(a,b,1,0,n-1);} private Dt Fge(int a,int b,int k,int l,int r){ if(r<a||b<l){return ie;} if(a<=l&&r<=b){return dat[k];} Flz(k); return Dt.Cm(Fge(a,b,k<<1,l,l+ha[k<<1]-1),Fge(a,b,(k<<1)+1,l+ha[k<<1],r)); } public void Add(int a,int b,long d1){Fad(a,b,1,0,n-1,d1);} private void Fad(int a,int b,int k,int l,int r,long d1){ if(a<=l&&r<=b){ dat[k]=Dt.Lm(dat[k],d1); dat[k]=Dt.Um(dat[k],d1,ha[k]); bo[k]=true; } else if(r>=a&&b>=l){ Flz(k); Fad(a,b,k<<1,l,l+ha[k<<1]-1,d1); Fad(a,b,(k<<1)+1,l+ha[k<<1],r,d1); dat[k]=Dt.Cm(dat[k<<1],dat[(k<<1)+1]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Flz(int k){ if(bo[k]&&ha[k]>1){ if(ha[k<<1]>0){ dat[k<<1]=Dt.Lm(dat[k<<1],dat[k].lz1); dat[k<<1]=Dt.Um(dat[k<<1],dat[k].lz1,ha[k<<1]); bo[k<<1]=true; } if(ha[(k<<1)+1]>0){ dat[(k<<1)+1]=Dt.Lm(dat[(k<<1)+1],dat[k].lz1); dat[(k<<1)+1]=Dt.Um(dat[(k<<1)+1],dat[k].lz1,ha[(k<<1)+1]); bo[(k<<1)+1]=true; } dat[k]=Dt.Cl(dat[k]); bo[k]=false; } } } public class Et{ private List<int>[] li; public int[] at2,ixl2,ixr2,fa; private int f=1,f2=1; public Et(List<int>[] li,int o){ int n=li.Length; this.li=li; at2=new int[n]; ixl2=new int[n]; ixr2=new int[n]; fa=new int[n+1]; Fu1(o,1); } private void Fu1(int a,int g){ at2[f2]=a; ixl2[a]=f2; f++;f2++; fa[a]=g; for(int i=0;i<li[a].Count;i++){ if(ixl2[li[a][i]]==0){ Fu1(li[a][i],g+1); f++; } } ixr2[a]=f2-1; } } public class Sc{ [MethodImpl(MethodImplOptions.AggressiveInlining)] protected virtual string Rl(){return Console.ReadLine();} [MethodImpl(MethodImplOptions.AggressiveInlining)] protected virtual string[] Sp(string st){return st.Split();} [MethodImpl(MethodImplOptions.AggressiveInlining)] private T Ct<T>(string s){return (T)Convert.ChangeType(s,typeof(T));} public virtual int I{get{return int.Parse(Rl());}} public virtual long L{get{return long.Parse(Rl());}} public virtual double D{get{return double.Parse(Rl());}} public virtual string S{get{return Rl();}} public int[] Ia{get{return Array.ConvertAll(Sp(Rl()),int.Parse);}} public long[] La{get{return Array.ConvertAll(Sp(Rl()),long.Parse);}} public double[] Da{get{return Array.ConvertAll(Sp(Rl()),double.Parse);}} public string[] Sa{get{return Sp(Rl());}} public object[] Oa{get{return Sp(Rl());}} public int[] Ia2{get{return Array.ConvertAll(Sp("0 "+Rl()+" 0"),int.Parse);}} public int[] Ia3(string a,string b){return Array.ConvertAll(Sp(a+Rl()+b),int.Parse);} public int[] Ia3(int a){return Array.ConvertAll(Sp(Rl()+" "+a.ToString()),int.Parse);} public long[] La2{get{return Array.ConvertAll(Sp("0 "+Rl()+" 0"),long.Parse);}} public long[] La3(string a,string b){return Array.ConvertAll(Sp(a+Rl()+b),long.Parse);} public long[] La3(int a){return Array.ConvertAll(Sp(Rl()+" "+a.ToString()),long.Parse);} public double[] Da2{get{return Array.ConvertAll(Sp("0 "+Rl()+" 0"),double.Parse);}} public double[] Da3(string a,string b){return Array.ConvertAll(Sp(a+Rl()+b),double.Parse);} public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;} public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;} public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Sp(Rl()));}return a;} public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Sp(Rl()));}return a;} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T,T) Tp2<T>(){var s=Sp(Rl());return (Ct<T>(s[0]),Ct<T>(s[1]));} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T,T,T) Tp3<T>(){var s=Sp(Rl());return (Ct<T>(s[0]),Ct<T>(s[1]),Ct<T>(s[2]));} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T,T,T,T) Tp4<T>(){var s=Sp(Rl());return (Ct<T>(s[0]),Ct<T>(s[1]),Ct<T>(s[2]),Ct<T>(s[3]));} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T,T,T,T,T) Tp5<T>(){var s=Sp(Rl());return (Ct<T>(s[0]),Ct<T>(s[1]),Ct<T>(s[2]),Ct<T>(s[3]),Ct<T>(s[4]));} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T,T,T,T,T,T) Tp6<T>(){var s=Sp(Rl());return (Ct<T>(s[0]),Ct<T>(s[1]),Ct<T>(s[2]),Ct<T>(s[3]),Ct<T>(s[4]),Ct<T>(s[5]));} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T1,T2) Tp2<T1,T2>(){var s=Sp(Rl());return (Ct<T1>(s[0]),Ct<T2>(s[1]));} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T1,T1,T2) Tp3<T1,T2>(){var s=Sp(Rl());return (Ct<T1>(s[0]),Ct<T1>(s[1]),Ct<T2>(s[2]));} } public class Scs:Sc{ private StreamReader sr; public Scs(string t){sr=new StreamReader(t);} [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override string Rl(){return sr.ReadLine();} } public class Sc2:Sc{ private string[] sps=new string[]{" "," ","\t"}; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override string[] Sp(string st){return st.Split(sps,StringSplitOptions.RemoveEmptyEntries);} public override int I{get{return int.Parse(Sp(Rl())[0]);}} public override long L{get{return long.Parse(Sp(Rl())[0]);}} public override double D{get{return double.Parse(Sp(Rl())[0]);}} public override string S{get{return Sp(Rl())[0];}} } public class Scs2:Sc2{ private StreamReader sr; public Scs2(string t){sr=new StreamReader(t);} [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override string Rl(){return sr.ReadLine();} } public class Sct:Sc{ private List<string> li=new List<string>(); private int l=0; public void Add(int s){li.Add(s.ToString());} public void Add(long s){li.Add(s.ToString());} public void Add(double s){li.Add(s.ToString());} public void Add(string s){li.Add(s.ToString());} public void Add(object s){li.Add(s.ToString());} public void Add(int[] s){li.Add(string.Join(" ",s));} public void Add(long[] s){li.Add(string.Join(" ",s));} public void Add(double[] s){li.Add(string.Join(" ",s));} public void Add(string[] s){li.Add(string.Join(" ",s));} public void Add(object[] s){li.Add(string.Join(" ",s));} protected override string Rl(){return li[l++];} public void Clear(){li.Clear();l=0;} }