#include <bits/stdc++.h>
using namespace std;
long long bss(vector<long long> &v,long long val){
long long l=0,r = v.size()-1;
while(l<=r){
long long mid = (l+r)/2;
if(v[mid]==val)return mid;
else if(v[mid] < val)l = mid+1;
else r = mid-1;
}
return -1;
}
// code for FenwickTree is taken from cp-algorithms.com
struct FenwickTree {
vector<long long> bit;
long long n;
FenwickTree(long long n) {
this->n = n;
bit.assign(n, 0);
}
FenwickTree(vector<long long> a) : FenwickTree(a.size()) {
for (size_t i = 0; i < a.size(); i++)
add(i, a[i]);
}
long long sum(long long r) {
long long ret = 0;
for (; r >= 0; r = (r & (r + 1)) - 1)
ret += bit[r];
return ret;
}
long long sum(long long l, long long r) {
return sum(r) - sum(l - 1);
}
void add(long long idx, long long delta) {
for (; idx < n; idx = idx | (idx + 1))
bit[idx] += delta;
}
};
struct Node{
vector<long long> dd;
vector<long long> ddv;
FenwickTree pref;
};
struct segment_tree{
vector<long long> h,a;
long long qr,last,N;
bool isposs;
vector<Node> T;
segment_tree(long long n){
N = n;
h.reserve(n+1);
a.reserve(n+1);
T.reserve(4*n+1);
}
void build(long long v,long long tl,long long tr){
if(tl!=tr){
long long tm = (tl+tr)/2;
build(2*v,tl,tm);
build(2*v+1,tm+1,tr);
}
T[v].dd.push_back(tl);
for(long long i=tl+1;i<=tr;i++){
if(h[i] > h[T[v].dd.back()])T[v].dd.push_back(i);
}
vector<long long> temp;
for(auto i : T[v].dd){
T[v].ddv.push_back(h[i]);
temp.push_back(a[i]);
}
T[v].pref = FenwickTree(temp);
}
void update(long long v,long long tl,long long tr,long long pos,long long change){
if(tl!=tr){
long long tm = (tl + tr) / 2;
if (pos <= tm)
update(v*2, tl, tm, pos,change);
else
update(v*2+1, tm+1, tr, pos,change);
}
long long ind = bss(T[v].dd,pos);
if(ind!=-1)T[v].pref.add(ind,change);
}
long long queryHelper(long long v,long long tl,long long tr,long long l,long long r){
if(l > r) return 0;
if (l == tl && r == tr) {
auto it = upper_bound(T[v].ddv.begin(),T[v].ddv.end(),last);
long long ind = it-T[v].ddv.begin();
if(r==qr){
if(it==T[v].ddv.end() || T[v].dd.back()!=qr){
isposs = false;
return -1;
}
else{
last = T[v].ddv.back();
return T[v].pref.sum(ind,T[v].ddv.size()-1);
}
}
else{
if(it!=T[v].ddv.end()){
last = T[v].ddv.back();
return T[v].pref.sum(ind,T[v].ddv.size()-1);
}
else{
return 0;
}
}
}
long long tm = (tl + tr) / 2;
return queryHelper(v*2, tl, tm, l, min(r, tm)) + queryHelper(v*2+1, tm+1, tr, max(l, tm+1), r);
}
long long query(long long l,long long r){
qr = r;
isposs = true;
last = -1;
long long ans = queryHelper(1,1,N,l,r);
if(isposs)return ans;
else return -1;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n,q;
cin >> n >> q;
segment_tree Front(n),Back(n);
for(long long i=1;i<=n;i++){
cin >> Back.h[i];
Front.h[n-i+1] = Back.h[i];
}
for(long long i=1;i<=n;i++){
cin >> Back.a[i];
Front.a[n-i+1] = Back.a[i];
}
Front.build(1,1,n);
Back.build(1,1,n);
while(q--){
long long type,s,e;
cin >> type >> s >> e;
if(type==1){
Back.update(1,1,n,s,e - Back.a[s]);
Back.a[s] = e;
Front.update(1,1,n,n-s+1,e - Front.a[n-s+1]);
Front.a[n-s+1] = e;
}
else cout << ( s < e ? Front.query(n-e+1,n-s+1) : Back.query(e,s) ) << '\n';
}
}