三种离散化

 

等有空再测试

```cpp

#define  debug(x) cerr<<#x<<" = "<<x<<endl
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int inf = 0x3f3f3f3f;
int n = 10, m, ans;
int a[] = {1, 55, 777, 5, 89, 433, 242, 55555555, 242, 777};
vector<int> hush(a, a + n);
int b[10], c[10];
void initHush1() {
    sort(hush.begin(), hush.end());
    auto it = unique(hush.begin(), hush.end());
    hush.resize(distance(hush.begin(), it));
}
inline int getId1(int x) {
    return distance(hush.begin(), lower_bound(hush.begin(), hush.end(), x));
}
void initHush2() {
    for (int i = 0; i < n; ++i) {
        b[i] = a[i];
    }
    sort(b, b + n);
    m = unique(b, b + n) - b;
}
inline int getId2(int x) {
    return lower_bound(b, b + m, x) - b;
}
struct Node {
    int val, pos;
    bool operator<(const Node &T) const {
        if (val == T.val)return pos < T.pos;
        return val < T.val;
    }
} V[10];
void initHush3() {
    for (int i = 0; i < n; ++i) {
        V[i].val = a[i];
        V[i].pos = i;
    }
    sort(V, V + n);
    for (int i = 1, j = 0; i < n; i++) {
        if (i == 1 || V[i].val != V[i - 1].val)j++;
        c[V[i].pos] = j;
    }
}
int getId3(int pos){
    return c[pos];
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    initHush1();
    initHush2();
    initHush3();
    debug(getId1(1));
    debug(getId1(55555));
    debug(getId2(1));
    debug(getId2(55555));
    debug(getId3(1));
    debug(getId3(5));
    return 0;
}
/*
8 5
1 4
3 6
4 5
4 6
4 7
*/

```

posted @ 2019-05-27 14:49  伍玖似十九  阅读(176)  评论(0编辑  收藏  举报