BZOJ 1588 HNOI2002 营业额统计 裸Treap .

题目大意:。。。题目描述不全看这里好了

给定一个序列 对于每个元素我们定义该数的最小波动值为这个数与前面所有数的差中的最小值(第一个数的最小波动值为第一个数本身) 求最小波动值之和

找最近的数只需要找前驱和后继就行了 平衡树的基本操作 不多说了

然后——

此题多组数据!!尼玛!!看题目描述这也是单组数据啊!!什么**情况??

而且多组数据尼玛也就算了!!输入数据还不全!!如果读到EOF需要按照0处理!尼玛这上哪里想去啊!

于是此题不看题解无法AC 鉴定完毕

60%达成 还剩四道题 水水吧。。。

  1. #include<cstdio>   
  2. #include<cstring>   
  3. #include<iostream>   
  4. #include<algorithm>   
  5. using namespace std;  
  6. struct abcd{  
  7.     abcd *ls,*rs;  
  8.     int key,num;  
  9.     abcd(int x);  
  10. }*null=new abcd(0),*root=null;  
  11. abcd :: abcd(int x)  
  12. {  
  13.     ls=rs=null;  
  14.     key=rand();  
  15.     num=x;  
  16. }  
  17. void Zig(abcd *&x)  
  18. {  
  19.     abcd *y=x->ls;  
  20.     x->ls=y->rs;  
  21.     y->rs=x;  
  22.     x=y;  
  23. }  
  24. void Zag(abcd *&x)  
  25. {  
  26.     abcd *y=x->rs;  
  27.     x->rs=y->ls;  
  28.     y->ls=x;  
  29.     x=y;  
  30. }  
  31. void Insert(abcd *&x,int y)  
  32. {  
  33.     if(x==null)  
  34.     {  
  35.         x=new abcd(y);  
  36.         return ;  
  37.     }  
  38.     if(y==x->num)  
  39.         return ;  
  40.     if(y<x->num)  
  41.     {  
  42.         Insert(x->ls,y);  
  43.         if(x->ls->key>x->key)  
  44.             Zig(x);  
  45.     }  
  46.     else  
  47.     {  
  48.         Insert(x->rs,y);  
  49.         if(x->rs->key>x->key)  
  50.             Zag(x);  
  51.     }  
  52. }  
  53. int Pred(abcd *x,int y)  
  54. {  
  55.     if(x==null)  
  56.         return 0xefefefef;  
  57.     if(y<x->num)  
  58.         return Pred(x->ls,y);  
  59.     return max( x->num , Pred(x->rs,y) );  
  60. }  
  61. int Secc(abcd *x,int y)  
  62. {  
  63.     if(x==null)  
  64.         return 0x7fffffff;  
  65.     if(y>x->num)  
  66.         return Secc(x->rs,y);  
  67.     return min( x->num , Secc(x->ls,y) );  
  68. }  
  69. int n,ans;  
  70. int main()  
  71. {  
  72.     int i,x;  
  73.     srand(19980402);  
  74.     while(~scanf("%d",&n) )  
  75.     {  
  76.         root=null;ans=0;  
  77.         for(i=1;i<=n;i++)  
  78.         {  
  79.             if(scanf("%d",&x)==EOF)x=0;  
  80.             int pred=Pred(root,x),secc=Secc(root,x);  
  81.                 if(i^1)  
  82.                 ans+=min( x-pred , secc-x );  
  83.             else  
  84.                 ans+=x;  
  85.             Insert(root,x);  
  86.         }     
  87.         cout<<ans<<endl;  
  88.     }  
  89. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值