#include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; using vi = vector; using vvi = vector; using vvvi = vector; using vll = vector; using vvll = vector; using vvvll = vector; using vmi = vector; using vvmi = vector; using vvvmi = vector; #define all(a) (a).begin(), (a).end() #define rep2(i, m, n) for (int i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) ll op(ll a, ll b){ return a+b; } ll e(){return 0;} int m = 100010; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; vll a(n); rep(i, n)cin >> a[i]; int b = 2*(int)sqrt(n); vector>> vseg(2); int i = 0; while(i < n){ vll s(m, 0), t(m, 0); rep(j, b){ s[a[i+j]]+=a[i+j]; t[a[i+j]]++; } segtree s1(s), s2(t); vseg[0].push_back(s1); vseg[1].push_back(s2); i += b; } while(q--){ int i; cin >> i; if(i == 1){ int x, y; cin >> x >> y; x--; int c = x/b; vseg[0][c].set(a[x], vseg[0][c].get(a[x]) - a[x]); vseg[1][c].set(a[x], vseg[1][c].get(a[x])-1); a[x] = y; vseg[0][c].set(a[x], vseg[0][c].get(a[x]) + a[x]); vseg[1][c].set(a[x], vseg[1][c].get(a[x]) + 1); }else{ ll l, r, x, y; cin >> l >> r >> x >> y; l--; r--; ll ans = 0; if(l/b == r/b){ rep2(k, l, r+1)ans += (a[k] < x) ? x : (a[k] > y ? y : a[k]); cout << ans << endl; continue; } rep2(j, l/b, r/b+1){ if(j == l/b){ rep2(k, l, (j+1)*b)ans += (a[k] < x) ? x : (a[k] > y ? y : a[k]); }else if(j == r/b){ rep2(k, j*b, r+1)ans += (a[k] < x) ? x : (a[k] > y ? y : a[k]); }else{ ans += vseg[0][j].prod(x, y+1) + vseg[1][j].prod(0, x)*x + vseg[1][j].prod(y+1, m)*y; } } cout << ans << endl; } } return 0; }