Nine degree OJ 15,412 fork Tree

Source: Internet
Author: User

Original title Link: http://ac.jobdu.com/problem.php?pid=1541
Inability to spit out the slot, C language in the global variable initial value is not 0 (pointer is a null pointer)?
That's why I'm so sick of my re!/(ㄒoㄒ)/~~ ...
Test instructions Nothing to say, set splay tree do. Specific as follows:

#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX_N 1100#define SIZE (_) (_) ==null 0: (_)->size)typedef struct _spt{int val, size; struct _SPT *pre, *ch[2];} Splay;splay *root = null, *null = NULL, Stack[max_n], *ptr[max_n];int sz =0; splay *_calloc (int val) {splay *p = &stack[sz++]; P->val = val, p->size =1; P->pre = p->ch[0] = p->ch[1] = null;returnP;} void Push_up (Splay *x) {if(x = = null)return; x->size = Size (x->ch[0]) + Size (x->ch[1]) +1;}    void rotate (splay *x, int d) {splay *y = x->pre; Y-&GT;CH[!D] = x->ch[d];if(x->ch[d]! = null) X->ch[d]->pre = y; X->pre = y->pre;if(Y->pre! = null) y->pre->ch[y->pre->ch[0]! = y] = x;    X->ch[d] = y;    Y->pre = x; Push_up (y), push_up (x);if(y = = root) root = x;} void Initialize () {null = _calloc (-1); Null->size =0; root = null;} void Update (Splay *x) {if(x! = null) {Update (x->ch[0]); Update (x->ch[1]);    PUSH_UP (x); }}void Gogo (int n) {int I, a, b; for(i =0; I <= N;    i++) {Ptr[i] = _calloc (i); } for(i =1; I <= N; i++) {scanf ("%d%d", &a, &b);if(-1= = A | | -1= = b) {if(-1= = a && b! =-1) ptr[i]->ch[1] = Ptr[b], ptr[b]->pre = Ptr[i];if(-1= = B && A! =-1) ptr[i]->ch[0] = Ptr[a], ptr[a]->pre = Ptr[i]; }Else{ptr[i]->ch[0] = Ptr[a], ptr[a]->pre = Ptr[i]; ptr[i]->ch[1] = Ptr[b], ptr[b]->pre = Ptr[i]; } push_up (Ptr[i]);if(Ptr[i]->pre = = null) root = Ptr[i]; } update (root);} int main () {#ifdef LOCALFreopen ("In.txt","R", stdin); Freopen ("OUT.txt","w+", stdout);#endifint N, t, I; Char buf[ -]; while(~SCANF ("%d", &n)) {sz =0, Initialize (), Gogo (n); scanf"%d", &t); while(t--) {scanf ('%s%d ', buf, &i);if(' s '= = buf[0]) {printf ("%d\n", ptr[i]->size); }Else if(' R '= = buf[0]){if(Ptr[i] = = root)Continue; Rotate (ptr[i], ptr[i]->pre->ch[0] = = Ptr[i]); }Else{if(Ptr[i] = = root) printf (" -1\n");Elseprintf"%d\n", Ptr[i]->pre->val); }        }    }return 0;}

Nine degree OJ 15,412 fork Tree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.