#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; constexpr int M = 200010; constexpr int B = 3125; int a[M], b[M]; int ans_memo[2 * M]; bool invalid[M]; int n; void dfs(int l_ask, int r_ask, int l_a, int r_a) { if (l_ask == r_ask) return; int c_ask = (l_ask + r_ask) / 2; int mn = 2 * INF; int imn = max(l_a, c_ask - (n - 1)); for (int ia = imn, iar = min({r_a, n, c_ask + 1}); ia < iar; ia++) { if (!invalid[ia] && chmin(mn, a[ia] + b[c_ask - ia])) imn = ia; } ans_memo[c_ask] = mn; dfs(l_ask, c_ask, l_a, imn + 1); dfs(c_ask + 1, r_ask, imn, r_a); } int P[M], X[M], K[M]; } int main() { ios::sync_with_stdio(false); cin.tie(0); int q; cin >> n >> q; rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, q) cin >> P[i] >> X[i] >> K[i], P[i]--, K[i] -= 2; int bl = 0, br = 0; rep(iq, q) { if (iq % B == 0) { bl = iq; br = min(iq + B, q); for (int i = bl; i < br; i++) invalid[P[i]] = true; dfs(0, 2 * n - 1, 0, n); for (int i = bl; i < br; i++) invalid[P[i]] = false; } a[P[iq]] = X[iq]; int ans = ans_memo[K[iq]]; for (int i = bl; i < br; i++) { int ia = P[i], ib = K[iq] - ia; if (0 <= ib && ib < n) chmin(ans, a[ia] + b[ib]); } cout << ans << '\n'; } }