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. CodeForces 478B 第八次比赛 B题

    Description n participants of the competition were split into m teams in some manner so that each te ...

  2. 将Vim改造为强大的IDE

    1.安装Vim和Vim基本插件 首先安装好Vim和Vim的基本插件.这些使用apt-get安装即可: lingd@ubuntu:~/arm$sudo apt-get install vim vim-s ...

  3. 【quartz】 理论知识

    属性的介绍 1.调度器属性:分别设置调度器的实例名(instanceName) 和实例 ID (instanceId).属性 org.quartz.scheduler.instanceName 可以是 ...

  4. ServiceStack.OrmLite 调用存储过程

    最近在做关于ServiceStack.OrmLite调用存储过程时,有问题.发现ServiceStack.OrmLite不能调用存储过程,或者说不能实现我想要的需求.在做分页查询时,我需要传入参数传出 ...

  5. C语言中的字符串拷贝函数strcpy和内存拷贝函数memcpy的区别与实现

    strcpy和memcpy都是标准C库函数,它们有下面的特点. strcpy提供了字符串的复制.即strcpy只用于字符串复制,并且它不仅复制字符串内容之外,还会复制字符串的结束符'\0'. 已知st ...

  6. python 安装 easy_intall 和 pip python无root权限安装

    http://www.cnblogs.com/haython/p/3970426.html easy_install和pip都是用来下载安装Python一个公共资源库PyPI的相关资源包的 首先安装e ...

  7. IntelliJ IDEA 比较当前版本文件与历史文件

    前言: 写代码修改后怎样比较与历史文件的区别呢?idea提供了2种比较方式(目前笔者所了解到的) 一.SVN的版本比较 二.当前文件与历史版本比较

  8. C# mongodb [下]

    概述 传统的关系数据库一般由数据库(database).表(table).记录(record)三个层次概念组成,MongoDB是由数据库(database).集合(collection).文档对象(d ...

  9. 【Android自学之旅】 Android开发环境的搭建

    [Android自学之旅] Android开发环境的搭建 搭建参考教程: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-do ...

  10. soap消息机制 讲解

    SOAP(Simple Object Access Protocol,简单对象访问协议)作为一种信息交互协议在分布式应用中非常广泛,如WebService.在使用.Net开发WebService时候, ...