Language: C++

#include<set>
#include<iostream>
#define rep(i,a,b)for(int i=a;i<b;++i)
typedef long long ll;
using namespace std;
int N,Q;
ll A[200001],B[200001];
multiset<ll>S;

int main(){
	ios::sync_with_stdio(0);
	cin>>N>>Q;
	rep(i,0,N<<1)cin>>A[i];
	rep(i,0,N<<1)cin>>B[i];
	ll ans=0;
	bool odd=0;
	ans+=A[0]+A[(n<<1)-1];
	rep(i,1,(N<<1)-1){
		ans+=max(A[i],B[i]);
		odd^=(A[i]>B[i]);
		S.insert(abs(A[i]-B[i]));
	}
	while(Q--){
		ll a,x,y;
		cin>>a>>x>>y;
		if(--a==0||a==(N<<1)-1){
			ans+=x-A[a];
			A[a]=x;
		}else{
			odd^=(A[a]>B[a]);
			odd^=(x>y);
			ans+=max(x, y)-max(A[a],B[a]);
			int*p=S.lower_bound(abs(A[a]-B[a]));
			S.erase();
			S.insert(abs(x-y));
			A[a]=x;
			B[a]=y;
		}
		cout<<(!odd?ans:ans-(*S.begin()))<<"\n";
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:22: error: 'n' was not declared in this scope
   17 |         ans+=A[0]+A[(n<<1)-1];
      |                      ^
a.cc:33:44: error: cannot convert 'std::multiset<long long int>::iterator' {aka 'std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator'} to 'int*' in initialization
   33 |                         int*p=S.lower_bound(abs(A[a]-B[a]));
      |                               ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
      |                                            |
      |                                            std::multiset<long long int>::iterator {aka std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator}
a.cc:34:32: error: no matching function for call to 'std::multiset<long long int>::erase()'
   34 |                         S.erase();
      |                         ~~~~~~~^~
In file included from /usr/include/c++/14/set:64,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_multiset.h:641:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::erase(const_iterator) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; const_iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator]'
  641 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_multiset.h:641:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_multiset.h:671:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::size_type std::multiset<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; size_type = long unsigned int; key_type = long long int]'
  671 |       erase(const key_type& __x)
      |       ^~~~~
/usr/include/c++/14/bits/stl_multiset.h:671:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_multiset.h:693:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::erase(const_iterator, const_iterator) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; const_iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator]'
  693 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_multiset.h:693:7: note:   candidate expects 2 arguments, 0 provided