#include #include using namespace std; class query { public: int t, a; long long b; query() : t(-1), a(-1), b(-1) {} }; class node { public: int p, l, r; node() : p(-1), l(-1), r(-1) {} }; class binary_tree { public: int root; vector v; binary_tree(int n) : root(-1), v(vector(n)) {} }; binary_tree cartesian_tree(int N, const vector& A) { binary_tree T(N); vector st; int pos = 0; for (int i = 0; i < N; i++) { int u = -1; while (!st.empty() && A[st.back()] < A[i]) { u = st.back(); st.pop_back(); } if (u != -1) { T.v[i].l = u; T.v[u].p = i; } if (!st.empty()) { T.v[i].p = st.back(); T.v[st.back()].r = i; } st.push_back(i); } T.root = st[0]; return T; } vector solve(int N, int Q, long long L, const vector& A, const vector& X, const vector& qs) { binary_tree T = cartesian_tree(N, A); vector s = X; auto build_tree = [&](auto& self, int x) -> void { if (T.v[x].l != -1) { self(self, T.v[x].l); s[x] += s[T.v[x].l]; } if (T.v[x].r != -1) { self(self, T.v[x].r); s[x] += s[T.v[x].r]; } }; build_tree(build_tree, T.root); vector CX = X; vector ans; for (query q : qs) { if (q.t == 1) { long long d = q.b - CX[q.a]; CX[q.a] = q.b; int pos = q.a; while (pos != -1) { s[pos] += d; pos = T.v[pos].p; } } if (q.t == 2) { int base = (A[q.a] < A[q.a + 1] ? q.a : q.a + 1); if (A[base] < L) { int pos = base; while (pos != T.root) { if (A[T.v[pos].p] >= s[pos] + L) { break; } pos = T.v[pos].p; } ans.push_back(s[pos] + L); } else { ans.push_back(L); } } } return ans; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, Q; long long L; cin >> N >> Q >> L; vector A(N), X(N); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { cin >> X[i]; } vector qs(Q); for (int i = 0; i < Q; i++) { cin >> qs[i].t >> qs[i].a; if (qs[i].t == 1) { cin >> qs[i].b; } qs[i].a--; } vector ans = solve(N, Q, L, A, X, qs); for (int i = 0; i < int(ans.size()); i++) { cout << ans[i] << '\n'; } return 0; }