zoukankan      html  css  js  c++  java
  • pipioj 1466: PIPI捡垃圾Ⅱ(平衡树or权值线段树)

    看了群友的平衡树stl板子,学到了orz

     1 #define bug(x) cout<<#x<<" is "<<x<<endl
     2 #define IO std::ios::sync_with_stdio(0)
     3 #include <bits/stdc++.h>
     4 #include <ext/pb_ds/tree_policy.hpp>
     5 #include <ext/pb_ds/assoc_container.hpp>
     6  using namespace  std;
     7 typedef long long ll;
     8 using namespace std;
     9 using namespace __gnu_pbds;
    10   
    11 tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> T;
    12  
    13 const int N=1e5+10;
    14  
    15 int n;
    16  
    17  
    18 int main(){
    19     IO;
    20     cin.tie(0),cout.tie(0);
    21     cin>>n;
    22     cout<<fixed<<setprecision(20);
    23     for(int i=1;i<=n;i++){
    24         int x,y;
    25         cin>>x;
    26         T.insert((1ll*x<<30)+i);//不能插入重复的值
    27         x=(*T.find_by_order(i/2-1)>>30);
    28         y=(*T.find_by_order(i/2)>>30);
    29         if(i%2)cout<<1.0*y<<'
    ';
    30         else cout<<0.5*(x+y)<<'
    ';
    31     }
    32      
    33  
    34  
    35     /*int q, opt, x;
    36   
    37     scanf("%d", &q);
    38     for (int i = 1; i <= q; ++ i)
    39     {
    40         scanf("%d%d", &opt, &x);
    41         if(opt == 1) 
    42             T.insert(x + i * 1e-6);
    43         //插入一个数
    44         if(opt == 2) 
    45             T.erase(T.lower_bound(x));
    46         //删除一个数
    47         if(opt == 3) 
    48             printf("%d
    ", (int)T.order_of_key(x) + 1);
    49         //查询一个数的排名
    50         if(opt == 4) 
    51             printf("%d
    ", (int)*T.find_by_order(x - 1));
    52         //查询第k小的数 返回的是一个迭代器 这里k是从0开始算的,意思是最小的数是第0小的
    53         if(opt == 5) 
    54             printf("%d
    ", (int)round(*(-- T.lower_bound(x))));
    55         //查询一个数的前驱
    56         if(opt == 6) 
    57             printf("%d
    ", (int)round(*T.lower_bound(x + 1)));
    58         //查询一个数的后继
    59     }
    60   
    61     return 0;*/
    62 }
  • 相关阅读:
    SSM环境搭建
    spring 开发 Tars
    Tars --- Hello World
    Java IO流
    Java集合
    常用类
    Pwn With longjmp
    格式化字符串漏洞利用实战之 njctf-decoder
    一步一步 Pwn RouterOS之ctf题练手
    srop实战
  • 原文地址:https://www.cnblogs.com/ccsu-kid/p/14297141.html
Copyright © 2011-2022 走看看