线段树/树状数组————离散化操作

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
const int N = 1e5 + 5;

vector<int>vec;

struct BIT {
    int c[N];
    void modify(int x, int k) {
        for (; x <= N; x += x & (-x)) {
            c[x] += k;
        }
    }
    int qurey(int x) {
        int ans = 0;
        for (; x; x -= x & (-x)) {
            ans += c[x];
        }
        return ans;
    }
}Tree;

//获得离散后x是第几大的
int get_idx(int x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin() + 1;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    for (int i = 1; i <= n; i++) {
        int l, r;
        cin >> l >> r;
        vec.push_back(l);
        vec.push_back(r);
    }
    //离散化核心操作,erase去重
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());

    return 0;
}

 

posted @ 2023-05-09 19:27  zhujio  阅读(23)  评论(0)    收藏  举报