Language: C++

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define all(v) (v).begin(),v.end()
#define np next_permutation
using namespace std;
using vi=vector<int>;
#define lp(i,n) for(int i=0;i<n;i++)
#define reps(i,j,n) for(int i=j;i<=n;i++)
#define vii vector<vi>
#define vb vector<bool>
#define pr pair<int,int>
#define vl vector<ll>
#define vs vector<string>
#define ump unordered_map<int,int>
#define Mpq priority_queue<int>
#define mpq priority_queue<int,vi,greater<int>> 
#define eb emplace_back
#define pr pair<int,int>
#define vp vector<pr>
#define ld long double
const int N=(int)2e5;



int n,q,x,y;
vi arr(N+1);
vector<multiset<int>> amap(N+1);
multiset<int> minofmax;
map<int,int> mp;

void solve(){
    cin>>n>>q;
    lp(i,n){
      cin>>x>>y;
      mp[i+1]=y; 
      arr[i+1]=x; 
    }
    for(auto &v:mp){
       amap[v.S].insert(arr[v.F]); 
    }
    for(int i=1;i<=N;i++){
        if(amap[i].empty()) continue;
        auto it=amap[i].rbegin();
        minofmax.insert(amap[i].rbegin()); 
    }
    while(q--){
       cin>>x>>y; 
       int prev=mp[x]; 
       mp[x]=y; 
       int prev_val=*(amap[prev].rbegin());
       amap[prev].erase(amap.find(arr[x]));
       
       if(arr[x]==prev_val){
          minofmax.erase(minofmax.find(arr[x]));
          if(!amap[prev].empty()){
             int cur_val=*(amap[prev].rbegin());
             minofmax.insert(cur_val);
          }
       }
   
       if(!amap[y].empty()){
          auto it=amap[y].rbegin();
          int val=*it;
          amap[y].insert(arr[x]);
          if(arr[x]>val){
             minofmax.erase(minmax.find(val));
             minofmax.insert(arr[x]);
          }
       }
       else{
          amap[y].insert(arr[x]);
          minofmax.insert(arr[x]);
       }
       cout<<*minofmax.rbegin()<<"\n";
    }
}

int main(int argc,char *argv[]){
   ios_base::sync_with_stdio(0);
   cin.tie(nullptr);   
   solve();
   return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:48:24: error: no matching function for call to 'std::multiset<int>::insert(std::multiset<int>::reverse_iterator)'
   48 |         minofmax.insert(amap[i].rbegin());
      |         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/set:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:158,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_multiset.h:553:9: note: candidate: 'template<class _InputIterator> void std::multiset<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  553 |         insert(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/14/bits/stl_multiset.h:553:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_multiset.h:504:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; value_type = int]'
  504 |       insert(const value_type& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_multiset.h:504:32: note:   no known conversion for argument 1 from 'std::multiset<int>::reverse_iterator' {aka 'std::reverse_iterator<std::_Rb_tree_const_iterator<int> >'} to 'const std::multiset<int>::value_type&' {aka 'const int&'}
  504 |       insert(const value_type& __x)
      |              ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_multiset.h:509:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(value_type&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; value_type = int]'
  509 |       insert(value_type&& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_multiset.h:509:27: note:   no known conversion for argument 1 from 'std::multiset<int>::reverse_iterator' {aka 'std::reverse_iterator<std::_Rb_tree_const_iterator<int> >'} to 'std::multiset<int>::value_type&&' {aka 'int&&'}
  509 |       insert(value_type&& __x)
      |              ~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_multiset.h:534:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(const_iterator, const value_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; value_type = int]'
  534 |       insert(const_iterator __position, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_multiset.h:534:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_multiset.h:539:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(const_iterator, value_type&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; value_type = int]'
  539 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_multiset.h:539:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_multiset.h:565:7: note: candidate: 'void std::multiset<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  565 |       insert(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_multiset.h:565:43: note:   no known conversion for argument 1 from 'std::multiset<int>::reverse_iterator' {aka 'std::reverse_iterator<std::_Rb_tree_const_iterator<int> >'} to 'std::initializer_list<int>'
  565 |       insert(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_multiset.h:585:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(node_type&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; node_type = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::node_type]'
  585 |       insert(node_type&& __nh)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_multiset.h:585:26: note:   no known conversion for argument 1 from 'std::multiset<int>::reverse_iterator' {aka 'std::reverse_iterator<std::_Rb_tree_const_iterator<int> >'} to 'std::multiset<int>::node_type&&' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::node_type&&'}
  585 |       insert(node_type&& __nh)
      |              ~~~~~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_multiset.h:590:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(const_iterator, node_type&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; node_type = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::node_type]'
  590 |       insert(const_iterator __hint, node_type&& __nh)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_multiset.h:590:7: note:   candidate expects 2 arguments, 1 provided
a.cc:55:30: error: 'class std::vector<std::multiset<int> >' has no member named 'find'
   55 |        amap[prev].erase(amap.find(arr[x]));
      |                              ^~~~
a.cc:70:36: error: overloaded function with no contextual type information
   70 |              minofmax.erase(minmax.find(val));
      |                                    ^~~~