• 【hihocoder 1329】 平衡树·Splay(set做法)


    【题目链接】:http://hihocoder.com/problemset/problem/1329

    【题意】

    【题解】

    因为一开始是空的树,所以;
    n其实就代表了树中的最多元素个数;
    则最坏的情况就是把所有元素都加进去;
    然后再全部都删掉吧;
    那也才2*n次操作;
    完全可以用set来一个一个删除那个区间的数字;
    lower_bound是大于等于那个数字的啊..

    【Number Of WA

    0

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define ms(x,y) memset(x,y,sizeof x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    
    int n,x,l,r;
    char s[3];
    set <int> myset;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
        cin >> n;
        rep1(i,1,n)
        {
            cin >> s;
            if (s[0]=='I')
            {
                cin >> x;
                myset.insert(x);
            }
            if (s[0]=='Q')
            {
                cin >> x;
                __typeof myset.begin() key;
                key = upper_bound(myset.begin(),myset.end(),x);
                key--;
                cout << *key<<endl;
            }
            if (s[0]=='D')
            {
                cin >> l >> r;
                while (1)
                {
                    __typeof myset.begin() key;
                    key = lower_bound(myset.begin(),myset.end(),l);
                    if (key==myset.end() || *key>r) break;
                    myset.erase(key);
                }
            }
        }
        return 0;
    }
    
  • 相关阅读:
    SysTick—系统定时器
    FreeRtos——单任务
    binutils工具集之---objdump
    对连接器的思考
    数组和指针并不相同
    typedef可以成为你的朋友
    gcc,一个神奇的编译器
    FreeRtos——移植
    Makefile 13——理解make的解析行为
    Makefile 12——改善编译效率
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626371.html
Copyright © 2020-2023  润新知