[破碎的状态] [-0] Hdu 4010
一个LCT的模版题
写错了好多次..
代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | #include<set> #include<map> #include<list> #include<queue> #include<stack> #include<string> #include<time.h> #include<math.h> #include<memory> #include<vector> #include<bitset> #include<fstream> #include<stdio.h> #include<utility> #include<sstream> #include<string.h> #include<iostream> #include<stdlib.h> #include<algorithm> using namespace std; const int maxn=300005; const int inf=1999999999; pair< int , int > p[300005]; struct node { int val; int max_val; int tag; bool rev_tag; node * ch[2]; node * father; }; int top=0; node * null; node * a[maxn]; node * new_node( int x) { static node a[300005]; node * t=&a[top++]; t->val=x; t->max_val=x; t->tag=0; t->rev_tag=0; t->ch[0]=null; t->ch[1]=null; t->father=null; return t; } void push_down(node * x) { if (x->rev_tag) { swap(x->ch[0],x->ch[1]); x->ch[0]->rev_tag^=1; x->ch[1]->rev_tag^=1; x->rev_tag= false ; } if (x->tag) { if (x->ch[0]!=null) { x->ch[0]->tag+=x->tag; x->ch[0]->max_val+=x->tag; x->ch[0]->val+=x->tag; } if (x->ch[1]!=null) { x->ch[1]->tag+=x->tag; x->ch[1]->max_val+=x->tag; x->ch[1]->val+=x->tag; } x->tag=0; } } int get_up(node * x) { if (x->father->ch[0]==x) return 0; if (x->father->ch[1]==x) return 1; return -1; } void rotate(node * &x, int c) { node * y=x->ch[c]; x->ch[c]=y->ch[!c]; y->ch[!c]->father=x; y->ch[!c]=x; y->father=x->father; x->father=y; y->max_val=x->max_val; x->max_val=max(x->val,max(x->ch[0]->max_val,x->ch[1]->max_val)); x=y; } void splay(node * x) { for (;;) { push_down(x->father->father); push_down(x->father); push_down(x); int t1=get_up(x); if (t1==-1) return ; int t2=get_up(x->father); if (t2==-1) { x=x->father; rotate(x,t1); return ; } int t3=get_up(x->father->father); if (t3==-1) { if (t1==t2) { x=x->father; x=x->father; rotate(x,t2); rotate(x,t1); } else { x=x->father; x=x->father; rotate(x->ch[t2],t1); rotate(x,t2); } } else { if (t1==t2) { x=x->father; x=x->father; x=x->father; rotate(x->ch[t3],t2); rotate(x->ch[t3],t1); x=x->ch[t3]; } else { x=x->father; x=x->father; rotate(x->ch[t2],t1); x=x->father; rotate(x->ch[t3],t2); x=x->ch[t3]; } } } } void access(node * &x) { for (;;) { splay(x); if (x->father==null) { x->ch[1]=null; x->max_val=max(x->val,x->ch[0]->max_val); return ; } splay(x->father); x->father->ch[1]=x; x->father->max_val=max(x->father->ch[0]->max_val,max(x->father->val,x->max_val)); } } void evert(node * x) { access(x); x->rev_tag= true ; } void merges(node * x,node * y) { evert(x); x->father=y; } int main() { #ifdef absi2011 freopen ( "input.txt" , "r" ,stdin); freopen ( "output.txt" , "w" ,stdout); #endif int n; null=new_node(-inf); null->ch[0]=null; null->ch[1]=null; null->father=null; for (; scanf ( "%d" ,&n)!=-1;) { top=1; int i; for (i=1;i<n;i++) { int x,y; scanf ( "%d %d" ,&x,&y); x--; y--; p[i]=make_pair(x,y); } for (i=0;i<n;i++) { int x; scanf ( "%d" ,&x); a[i]=new_node(x); } for (i=1;i<n;i++) { merges(a[p[i].first],a[p[i].second]); } int m; scanf ( "%d" ,&m); for (i=0;i<m;i++) { int oper; scanf ( "%d" ,&oper); int x,y; if (oper==1) { scanf ( "%d%d" ,&x,&y); x--; y--; evert(a[x]); access(a[y]); if ((a[x]->father!=null)||(x==y)) { printf ( "-1\n" ); continue ; } merges(a[x],a[y]); } else if (oper==2) { scanf ( "%d%d" ,&x,&y); x--; y--; evert(a[x]); access(a[y]); if ((a[x]->father==null)||(x==y)) { printf ( "-1\n" ); continue ; } a[y]->ch[0]->father=null; a[y]->ch[0]=null; a[y]->max_val=a[y]->val; } else if (oper==3) { int z; scanf ( "%d" ,&z); scanf ( "%d%d" ,&x,&y); x--; y--; evert(a[x]); access(a[y]); if ((a[x]->father==null)&&(x!=y)) { printf ( "-1\n" ); continue ; } a[y]->tag+=z; a[y]->val+=z; a[y]->max_val+=z; } else { scanf ( "%d%d" ,&x,&y); x--; y--; evert(a[x]); access(a[y]); if ((a[x]->father==null)&&(x!=y)) { printf ( "-1\n" ); continue ; } printf ( "%d\n" ,a[y]->max_val); } } printf ( "\n" ); } return 0; } |
大约 1 年前
The Board model paper" typically refers to a sample or model question paper that is designed by educational boards or institutions for various exams. These papers serve as practice material for students preparing for exams, providing them with an idea of the question format, difficulty level, and the type of content that may be covered in the actual examination. boardmodelpaper.com Model papers are usually created for specific subjects or courses. They cover a range of topics and chapters that students are expected to have studied during the academic term. Students often use these educational board model papers as an integral part of their exam preparation strategy, helping them familiarize themselves with the exam pattern and refine their understanding of the subject matter.