module mod_segment_tree
  implicit none
  integer(8), parameter :: DEFAULT = -100000000000000000_8
  type segment_tree
    integer :: n, p
    integer(8), pointer :: arr(:) => null()
  end type segment_tree
  private
  public :: segment_tree, init_segtree, update, query, DEFAULT
contains
  integer(8) function op(x,y)
    implicit none
    integer(8) :: x, y
    op = max(x,y)
    return
  end function op
  subroutine init_segtree(st,n)
    implicit none
    type(segment_tree) :: st
    integer, intent(in) :: n
    integer :: p
    p = 1
    do while (p.lt.n)
      p = 2*p
    end do
    st%n = n
    st%p = p
    allocate(st%arr(2*p-1))
    st%arr = DEFAULT
    return
  end subroutine init_segtree
  subroutine update(st,i,v)
    implicit none
    type(segment_tree) :: st
    integer, intent(in) :: i
    integer(8), intent(in) :: v
    integer :: x
    x = i+st%p-1
    st%arr(x) = v
    do while (x > 1)
      x = x/2
      st%arr(x) = op(st%arr(2*x),st%arr(2*x+1))
    end do
    return
  end subroutine update
  integer(8) function query(st,a,b)
    type(segment_tree) :: st
    integer, intent(in) :: a, b
    integer :: l, r
    query = DEFAULT
    l = a+st%p-1
    r = b+st%p-1
    do while (l <= r)
      if (mod(l,2) == 1) then
        query = op(query,st%arr(l))
        l = l+1
      end if
      if (mod(r,2) == 0) then
        query = op(query,st%arr(r))
        r = r-1
      end if
      l = l/2
      r = r/2
    end do
    return
  end function query
end module mod_segment_tree
program paired_parentheses
  use mod_segment_tree
  implicit none
  type(segment_tree) :: st1, st2
  integer :: n, q, p, pnum = 0, i
  integer(8) :: a(200000) = 0_8, b(200000) = 0_8, x, y
  integer(8) :: atot, ptot = 0_8
  read(*,*) n, q
  read(*,*) a(1:2*n)
  read(*,*) b(1:2*n)
  call init_segtree(st1,2*n)
  call init_segtree(st2,2*n)
  atot = sum(a(1:2*n))
  do i = 2, 2*n-1
    if (b(i) >= a(i)) then
      ptot = ptot+b(i)-a(i)
      pnum = pnum+1
      call update(st1,i,a(i)-b(i))
    else
      call update(st2,i,b(i)-a(i))
    end if
  end do
  do i = 1, q
    read(*,*) p, x, y
    atot = atot-a(p)
    if ((.not.(p == 1 .or. p == 2*n)).and.(b(p) >= a(p))) then
      ptot = ptot-b(p)+a(p)
      pnum = pnum-1
    end if
    a(p) = x
    b(p) = y
    atot = atot+a(p)
    if ((.not.(p == 1 .or. p == 2*n)).and.(b(p) >= a(p))) then
      ptot = ptot+b(p)-a(p)
      pnum = pnum+1
    end if
    if (.not.(p == 1 .or. p == 2*n)) then
      if (b(p) >= a(p)) then
        call update(st1,p,DEFAULT)
        call update(st2,p,a(p)-b(p))
      else
        call update(st1,p,b(p)-a(p))
        call update(st2,p,DEFAULT)
      end if
    end if
    if (mod(pnum,2) == 0) then
      write(*,'(i0)') atot+ptot
    else
      write(*,'(i0)') atot+ptot+max(query(st1,2,2*n-1),query(st2,2,2*n-1))
    end if
  end do
  stop
end program paired_parentheses