zoukankan      html  css  js  c++  java
  • (vector水平衡树)【模板】普通平衡树 Luogu P3369

    20行写完极其害怕

    只能跑1e5的数据,那个1e6强制在线的开o2只有20pts QAQ

    不用reserve也可以过,不过开了之后200ms的点只要130-140ms

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define fastio ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    const int maxn = 2e5 + 10;
    const ll inf = 1e17;
    ll mod = 1e9 + 7;
    
    vector<int>a;
    
    int main()
    {
        //freopen("C:\1.in", "r", stdin);
        fastio;
        int n;
        cin >> n;
        a.reserve(100010);//提前开空间跑得更快
        while (n--)
        {
            int o, x;
            cin >> o >> x;
            if (o == 1)
                a.insert(lower_bound(a.begin(), a.end(), x), x);
            else if (o == 2)
                a.erase(lower_bound(a.begin(), a.end(), x));
            else if (o == 3)
                cout << lower_bound(a.begin(), a.end(), x) - a.begin() + 1 << endl;
            else if (o == 4)
                cout << a[x - 1] << endl;
            else if (o == 5)
                cout << *(lower_bound(a.begin(), a.end(), x) - 1) << endl;
            else
                cout << *upper_bound(a.begin(), a.end(), x) << endl;
        }
        return 0;
    
    }
    
  • 相关阅读:
    SQL Server 2005存储过程示例
    SQL Server 存储过程
    SQL Server 2005存储过程示例
    转正申请书
    SQL注入天书
    转:毕业半年,我是如何从一名程序员成长为一名项目经理
    DIMFOM
    MONSA
    GLOBSYMM
    MASSHA
  • 原文地址:https://www.cnblogs.com/ruanbaiQAQ/p/13610447.html
Copyright © 2011-2022 走看看