#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

struct FenwickTree {
    vector<ll> bit;
    
    FenwickTree(int n) {
        bit.assign(n + 1, 0);
    }
    
    void add(int pos, ll val) {
        for(++pos; pos < bit.size(); pos += pos & -pos)
            bit[pos] += val;
    }
    
    ll sum(int pos) {
        ll res = 0;
        for(++pos; pos > 0; pos -= pos & -pos)
            res += bit[pos];
        return res;
    }
    
    ll rangeSum(int l, int r) {
        return sum(r) - sum(l - 1);
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, q;
    cin >> n >> q;
    
    vector<int> p(n + 1);
    vector<int> pos(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> p[i];
        pos[p[i]] = i;
    }
    
    FenwickTree normal(n);
    FenwickTree permuted(n);
    
    while(q--) {
        int type;
        cin >> type;
        
        if(type == 0) {
            int l, r, c;
            cin >> l >> r >> c;
            for(int i = l; i <= r; i++) {
                normal.add(i - 1, c);
            }
        }
        else if(type == 1) {
            int l, r, c;
            cin >> l >> r >> c;
            for(int i = l; i <= r; i++) {
                permuted.add(p[i] - 1, c);
            }
        }
        else if(type == 2) {
            int l, r;
            cin >> l >> r;
            cout << normal.rangeSum(l - 1, r - 1) << "\n";
        }
        else {  // type == 3
            int l, r;
            cin >> l >> r;
            ll sum = 0;
            for(int i = l; i <= r; i++) {
                int idx = p[i] - 1;
                sum += normal.sum(idx) + permuted.sum(idx);
            }
            cout << sum << "\n";
        }
    }
    
    return 0;
}