1 条题解

  • 1
    @ 2024-4-11 18:44:16

    离散化裸题,排序后去重,然后使用lower_bound查询序号即可,需要注意序号从1开始,因此lower_bound的查询结果需要加1。

    核心代码
    
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        v.push_back(a[i]);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for (int i = 1; i <= n; i++)
        cout << lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1 << " ";
    
    • 1

    信息

    ID
    711
    时间
    1000ms
    内存
    256MiB
    难度
    3
    标签
    (无)
    递交数
    44
    已通过
    24
    上传者