
PBDS
#include<bits/stdc++.h>
#define pii pair<int,int>
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
//declare
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>;
const int maxn = 2e5+5;
int n,q,salary[maxn],timer;
ordered_set st;
//
signed main(){
fastio;
cin>>n>>q;
for(int i=1;i<=n;i++){
int x; cin>>x;
salary[i] = x;
st.insert({x,timer++});
}
while(q--){
char op; cin>>op;
int a,b; cin>>a>>b;
if(op == '!'){
pii p = {salary[a],0};
st.erase(st.find_by_order(st.order_of_key(p)));
salary[a] = b;
st.insert({b,timer++});
}
else{
pii p = {b+1,0}, q = {a,0};
cout<<st.order_of_key(p)-st.order_of_key(q)<<"\n";
}
}
return 0;
}

發佈留言