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. SQLdiag Utility

    使用SQLdiag 会进行信息搜集类型 Windows 系统性能日志 Windows 系统日志 SQL Server 性能信息 SQL Server 阻塞信息 SQL Server 配置信息 如何使用 ...

  2. Java枚举常见7种用法

    DK1.5引入了新的类型——枚举.在 Java 中它虽然算个“小”功能,却给我的开发带来了“大”方便.用法一:常量在JDK1.5 之前,我们定义常量都是: publicstaticfianl…… .现 ...

  3. 【转载】link和@import的区别

    link和@import的区别 原文地址:http://www.cnblogs.com/zbo/archive/2010/11/17/1879590.html 页面中使用CSS的方式主要有3种:行内添 ...

  4. cocos3.2版本中的一些新特性

    1.设置屏幕分辨率的大小,需要手动添加: 2.去掉了所有CC开头的命名: 3.所有的单例(以前是采用shared开头方法),全部改为getInstance(); 4.cocos3.x以上的版本支持C+ ...

  5. Connectify是一款很实用的免费软件。能把计算机变成一个无线路由器

    Connectify是一款很实用的免费软件.能把计算机变成一个无线路由器.它能通过您计算机上的无线网卡发射一个无线AP,让有WiFi功能的设备(手机.笔记本)上网.3.0版以前仅支持32位Window ...

  6. javacript中的mvc设计模式

    以下内容为原创翻译,翻译不对的地方还请原谅,凑合着看吧. 原文网址是: 来源:http://www.alexatnet.com/articles/model-view-controller-mvc-j ...

  7. Wireshark技巧-过滤规则和显示规则

    Wireshark是一个强大的网络协议分析软件,最重要的它是免费软件. 过滤规则 只抓取符合条件的包,在Wireshark通过winpacp抓包时可以过滤掉不符合条件的包,提高我们的分析效率. 如果要 ...

  8. Thinkphp中路由Url获取的使用方法

    Thinkphp是一个体系较为完整的框架,很多地方比国外的框架功能都全,唯一不喜之处是性能,和传说中的.NET有点像. Thinkphp提供较全url处理体系,通过同一规则实现Url的路由和Url生成 ...

  9. angular入门系列教程2

    主题: 本篇主要介绍下angular里的一些概念,并且在咱们的小应用上加上点料.. 概念(大概了解即可,代码中遇到的会有详细注释): 模板:动态模板,是动态的,直接去处理DOM的,而不是通过处理字符串 ...

  10. Ubuntu C++环境支持

    问题描述:         在Ubuntu中默认安装有gcc,但是只能编辑C程序,现在希望添加C++环境支持 问题解决:         首先是配置gcc,在ubuntu安装完成已经有gcc了(gcc ...