QOJ.ac

QOJ

Type: Editorial

Status: Open

Posted by: Lynn_Sue

Posted at: 2026-09-04 13:33:56

Last updated: 2026-09-04 14:03:58

Back to Problem

有 set

全局最小值本来应该用堆维护,但是他现在要求是修改对应下标的元素怎么办?

把二元组 $(A_i, i)$ 丢入 set,修改改为先删后加即可。查询直接查第一个二元组的 second

#include<bits/stdc++.h>
using namespace std;
int n, q, a[100005];
set< pair<int, int> > S;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        S.insert({a[i], i});
    }
    cin >> q;
    while (q--){
        int op;
        cin >> op;
        if (op == 1){
            int i, x;
            cin >> i >> x;
            S.erase(S.lower_bound({a[i], i}));
            S.insert({a[i] = x, i});
        }else
            cout << S.begin() -> second << "\n";
    }
    return 0;
}

Comments

No comments yet.