#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector answers; for (int _ = 0; _ < Q; _++) { int type; cin >> type; if (type == 1) { int x; long long y; cin >> x >> y; A[x - 1] = y; } if (type == 2) { int l, r; long long a, b; cin >> l >> r >> a >> b; long long ans = 0; for (int i = l - 1; i < r; i++) { ans += max(a, min(b, A[i])); } answers.push_back(ans); } } for (auto v : answers) { cout << v << '\n'; } return 0; }