#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; constexpr int INF = 1001001001; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; VI a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; VI t(n), k(q); int sz1 = bit_ceil(0U + q); vector> add_queries(2 * sz1); auto reg = [&](int i, int x, int l, int r) { l += sz1, r += sz1; while (l < r) { if (l & 1) add_queries[l++].emplace_back(i, x); if (r & 1) add_queries[--r].emplace_back(i, x); l >>= 1; r >>= 1; } }; rep(i, q) { int p, x; cin >> p >> x >> k[i]; p--, k[i] -= 2; reg(p, a[p], t[p], i); a[p] = x, t[p] = i; } rep(i, n) reg(i, a[i], t[i], q); int sz2 = bit_ceil(0U + 2 * n - 1); int log2 = countr_zero(0U + sz2); VI d(2 * sz2, -1); vector

hist; auto cmp = [&](int p, int q, int k) { int pb = k - p, qb = k - q; if (pb >= n) return false; if (qb < 0) return true; return a[p] + b[pb] < a[q] + b[qb]; }; auto get = [&](int k) { int k2 = sz2 + k; int res = 2 * INF; for (int i = log2; i >= 0; i--) { int p = d[k2 >> i]; int pb = k - p; if (p != -1 && 0 <= pb && pb < n) chmin(res, a[p] + b[pb]); } return res; }; auto dfs1 = [&](auto&& self, int u, int l, int r) -> void { int now = ssize(hist); for (auto [p, x] : add_queries[u]) { a[p] = x; auto dfs2 = [&](auto&& self, int u, int l, int r, int p) -> void { int q = d[u]; hist.emplace_back(u, q); if (q == -1) { d[u] = p; return; } if (p > q) swap(p, q); if (l + 1 == r) { d[u] = cmp(p, q, l) ? p : q; } else { int c = (l + r) / 2; if (cmp(p, q, c)) { d[u] = p; self(self, 2 * u + 1, c, r, q); } else { d[u] = q; self(self, 2 * u, l, c, p); } } }; dfs2(dfs2, 1, 0, sz2, p); } if (l + 1 == r) { int iq = u - sz1; if (iq < q) cout << get(k[iq]) << '\n'; } else { int c = (l + r) / 2; self(self, 2 * u, l, c); self(self, 2 * u + 1, c, r); } while (ssize(hist) != now) { auto [v, p] = hist.back(); hist.pop_back(); d[v] = p; } }; dfs1(dfs1, 1, 0, sz1); }