离散化

离散化

离散化

1、用途

在需要利用到数字相对大小的题目中,将大数一一映射到小数上,缩小数据规模

2、原理

哈希

3、复杂度

离散化:\(O(nlogn)\)

查询:\(O(logn)\)

4、模板

function <int(vector <int> &, int)> gtIdx = [&](vector <int> &alls, int now)
{
    return upper_bound(alls.begin(), alls.end(), now) - alls.begin() + 1;
};
//+1:从1开始
sort(alls.begin(), alls.end());
alls.erase(unique(alls.begin(), alls.end()), alls.end());

例题

AcWing 802 区间和

posted @ 2020-08-31 16:08  Lecxcy  阅读(159)  评论(0编辑  收藏  举报