(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;

}
posted @ 2020-09-03 20:28  Lecoww  阅读(97)  评论(0)    收藏  举报