Runtime Error 到现在连样例也跑不出来!!!

调试了一晚上快要死了……

知道错在哪里但是不会改,代码先扔在这里吧。看来不能太依赖模板啊orz……

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> using namespace std; struct Node
{
Node *ch[];
int v; //节点编号
int s; //节点域
int flip;
Node( int v ):v(v)
{
ch[] = ch[] = NULL;
s = ;
flip = ;
}
int cmp( int x ) const
{
int t = ( ch[] == NULL ) ? : ch[]->s;
if ( t >= x ) return ;
if ( t + == x ) return -;
return ;
}
void maintain()
{
s = ;
if ( ch[] != NULL ) s += ch[]->s;
if ( ch[] != NULL ) s += ch[]->s;
return;
}
void pushDown()
{
if ( flip )
{
flip = ;
swap( ch[], ch[] );
if ( ch[] != NULL ) ch[]->flip = !ch[]->flip;
if ( ch[] != NULL ) ch[]->flip = !ch[]->flip;
}
}
}; struct number
{
int val;
int i;
}; const int MAXN = ; int n;
number num[MAXN];
int SA[MAXN]; void Rotate( Node* &o, int d ) //d=0 左旋 d=1 右旋
{
Node *k = o->ch[ d ^ ];
o->ch[ d ^ ] = k->ch[d];
k->ch[d] = o;
o = k;
o->ch[d]->maintain();
o->maintain();
return;
} void splay( Node* &o, int k )
{
o->pushDown();
int d = o->cmp(k);
if ( d == )
{
if ( o->ch[] != NULL )
k -= o->ch[]->s;
--k;
}
if ( d != - )
{
Node *p = o->ch[d];
p->pushDown();
int d2 = p->cmp(k);
int k2 = k;
if ( d2 == )
{
if ( p->ch[] != NULL )
k2 -= p->ch[]->s;
--k2;
}
if ( d2 != - )
{
splay( p->ch[d2], k2 );
if ( d == d2 ) Rotate( o, d ^ );
else Rotate( o->ch[d], d );
}
Rotate( o, d ^ );
}
return;
} void build( Node* &o, int l, int r )
{
int m = ( l + r ) >> ; o = new Node( m );
if ( l < m ) build( o->ch[], l, m - );
if ( r > m ) build( o->ch[], m + , r );
o->maintain(); return;
} void DFS( Node *cur )
{
cur->pushDown();
if ( cur->ch[] ) DFS( cur->ch[] );
//if ( cur->v && cur->v != n + 1 )
printf( "num=%d id=%d\n", SA[cur->v], cur->v );
if ( cur->ch[] ) DFS( cur->ch[] );
return;
} bool cmp( number a, number b )
{
if ( a.val == b.val ) return a.i < b.i;
return a.val < b.val;
} int Search( Node *o, int x )
{
int res = ;
while ( o != NULL )
{
o->pushDown();
int d;
if ( x == o->v ) d = -;
else if ( x < o->v ) d = ;
else d = ; printf("search=%d\n", o->v ); if ( d == - )
{
if ( o->ch[] != NULL )
res += o->ch[]->s;
++res;
return res;
}
else
{
if ( o->v == && x == )
{
printf("%d\n", o->ch[]->v );
puts("@@@");
}
if ( d == )
{
if ( o->ch[] != NULL )
res += o->ch[]->s;
++res;
}
o = o->ch[d];
}
}
return -;
} Node *root; Node *Merge( Node *left, Node *right )
{
splay( left, left->s );
left->ch[] = right;
left->maintain();
return left;
} void RemoveRoot()
{
Node *tmp = root;
root = Merge( root->ch[], root->ch[] );
delete tmp;
return;
} int main()
{
while ( scanf( "%d", &n ), n )
{
for ( int i = ; i <= n; ++i )
{
scanf("%d", &num[i].val );
num[i].i = i;
} root = NULL;
build( root, , n );
sort( num + , num + n + , cmp ); for ( int i = ; i <= n; ++i ) SA[ num[i].i ] = num[i].val;
//DFS( root );
for ( int i = ; i <= n; ++i )
{
int id = Search( root, num[i].i );
printf( "num = %d %d %d\n", num[i].val, num[i].i, id );
splay( root, id );
DFS(root);
if ( i ) putchar(' '); int tmp;
if ( root->ch[] ) tmp = i + root->ch[]->s;
else tmp = i;
printf( "%d\n\n", tmp ); root->ch[]->flip ^= ; RemoveRoot();
}
puts("");
}
return ;
}

UVa 1402 Runtime Error 伸展树的更多相关文章

  1. UVa 11922 - Permutation Transformer 伸展树

    第一棵伸展树,各种调试模板……TVT 对于 1 n 这种查询我处理的不太好,之前序列前后没有添加冗余节点,一直Runtime Error. 后来加上冗余节点之后又出了别的状况,因为多了 0 和 n+1 ...

  2. UVA 11922 Permutation Transformer —— splay伸展树

    题意:根据m条指令改变排列1 2 3 4 … n ,每条指令(a, b)表示取出第a~b个元素,反转后添加到排列尾部 分析:用一个可分裂合并的序列来表示整个序列,截取一段可以用两次分裂一次合并实现,粘 ...

  3. runtime error 的原因

    1.  数组访问越界 2.  分母为 0 3.   括号 做题时偶然发现的! (详见 UVA 10158 War) 代码中出现了这种东西 else if( arefriends(x,y==-1)  ) ...

  4. AVL树和伸展树 -数据结构(C语言实现)

    读数据结构与算法分析 AVL树 带有平衡条件的二叉树,通常要求每颗树的左右子树深度差<=1 可以将破坏平衡的插入操作分为四种,最后通过旋转恢复平衡 破坏平衡的插入方式 描述 恢复平衡旋转方式 L ...

  5. com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Cannot assign requested address: bind

    在发布 web service 时报错: Endpoint.publish(publishAddress, hl7MessageReveiver); com.sun.xml.internal.ws.s ...

  6. Arcmap 安装完后使用出现visual fortran run-time error的解决方法

    今天将ArcGIS安装到自己的XP笔记本上,安装过程一帆风顺,但打开Arcmap使用的时候,出现了visual fortran run-time error. 下面是解决方法: 下载个Dforrt.d ...

  7. Qt Sqlite qwt 发布过程中碰到的问题runtime error

    qt版本:4.8.0 qwt版本:6.1.2 使用dll show检测缺少的dll,或者笨一点的方法,点击运行差什么找什么放进去: 左上显示exe调用哪些dll,右边是dll又再次调用啦哪些dll: ...

  8. Splay伸展树学习笔记

    Splay伸展树 有篇Splay入门必看文章 —— CSDN链接 经典引文 空间效率:O(n) 时间效率:O(log n)插入.查找.删除 创造者:Daniel Sleator 和 Robert Ta ...

  9. Codeforce - Runtime Error

    Bahosain was trying to solve this simple problem, but he got a Runtime Error on one of the test case ...

随机推荐

  1. Linux内核目录

    linux目录结构 目录 1.树状目录结构图 2./目录 3./etc/目录 4./usr/目录 5./var/目录 6./proc/目录 7./dev/目录 该文章主要来自于网络进行整理. 目录结构 ...

  2. glog使用

    How To Use Google Logging Library Glog 的基本使用方法在google code上有介绍:How To Use Google Logging Library ;最好 ...

  3. libcurl安装

    sudo apt-get install libcurl4-openssl-dev -lcurl

  4. Ha ha lou!

    忙了一个晚上,终于稍微把这个模板修缮好了一点=-=//,然而我并不知道怎么像别的大牛一样,博客跟自己做的页面一样.总之今天就先到这里啦! 我的QQ是270115270,不知道会不会有人来呢=-=. ( ...

  5. 64bit Ubuntu, Android AAPT, R.java

    Ubuntu 13.10 aapt: error while loading shared libraries: libstdc++.so.6: cannot open shared object f ...

  6. mvc异步表单遇到的问题

    1,mvc异步表单遇到的问题    问题:使用jqury easy ui 时提交异步数据不能请求到服务器   解决办法:经过细心调试和检测,发现jqury的加载顺序放在了easy ui之后,所以首先加 ...

  7. DevExpress控件使用系列--ASPxUploadControl(图片上传及预览)

        1.控件功能     列表控件展示数据.弹框控件执行编辑操作.Tab控件实现多标签编辑操官方说明 2.官方示例       2.1 ASPxImage                http: ...

  8. javascript数学计算

    ◎Math.ceil()执行向上舍入,即它总是将数值向上舍入为最接近的整数:◎Math.floor()执行向下舍入,即它总是将数值向下舍入为最接近的整数:◎Math.round()执行标准舍入,即它总 ...

  9. MySql修改默认端口号,修改my.ini的端口号

    MySql默认端口号为3306,如果安装多个或者冲突需要修改端口号,修改my.ini的端口号就可以了,文件一般情况下在安装目录下.下面是具体说明: 方法/步骤 先在服务里停止mysql的服务器,再找到 ...

  10. android 关于InputDispatcher出现Consumer错误的解决办法

    原地址:http://www.educity.cn/wenda/158744.html android 关于InputDispatcher出现Consumer异常的解决方法10-23 03:24:46 ...