#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; struct SegmentTree { private: int n; vector> node; vector> sum; public: SegmentTree(vector v) { int sz = v.size(); n = 1; while (sz > n) n *= 2; node.resize(2 * n - 1); sum.resize(2 * n); for (ll i = 0; i < sz; i++) { node[i + n - 1].push_back(v[i]); } for (ll i = sz; i + n - 1 < node.size(); i++) { node[i + n - 1].push_back(0); } for (ll i = n - 2; i >= 0; i--) { node[i].resize(node[i * 2 + 1].size() + node[i * 2 + 2].size()); merge(node[i * 2 + 1].begin(), node[i * 2 + 1].end(), node[i * 2 + 2].begin(), node[i * 2 + 2].end(), node[i].begin()); } for (ll i = 0; i < node.size(); i++) { sum[i].resize(node[i].size() + 1); for (ll j = 0; j < node[i].size();j++) { sum[i][j + 1] = sum[i][j] + node[i][j]; } } } ll query(ll a, ll b, ll v, ll k = 0, ll l = 0, ll r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return 0; if (a <= l && r <= b) { ll idx = lower_bound(node[k].begin(), node[k].end(), v) - node[k].begin(); return sum[k].back() - sum[k][idx] - (node[k].size() - idx) * v; } ll vl = query(a, b, v, 2 * k + 1, l, (l + r) / 2); ll vr = query(a, b, v, 2 * k + 2, (l + r) / 2, r); return vl + vr; } }; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll n, q; scanf("%lld %lld", &n, &q); vector a(n); for (ll i = 0; i < n; i++) scanf("%lld", &a[i]); SegmentTree seg(a); while (q--) { ll t; scanf("%lld", &t); if (t == 1) { ll l, r, x; scanf("%lld %lld %lld", &l, &r, &x); l--; printf("%lld\n", seg.query(l, r, x)); } } return 0; }