inlinevoidinit(int n){ while (len * len <= n) len++; len--; } inlineintget_id(int i){return (i % len == 0) ? (i / len) : (i / len + 1); }
inlinevoidupdate_one(int i, longlong x){ a[i] += x; part[get_id(i)] += x; } inlinevoidupdate_part(int i, longlong x){ lazy[i] += x; } inlinevoidupdate(int l, int r, longlong x){ while (l % len != 1) update_one(l++, x); while (r % len != 0) update_one(r--, x); for (int i = get_id(l); i <= get_id(r); i++) update_part(i, x); }
inlinelonglongask_one(int i){ return a[i] + lazy[get_id(i)]; } inlinelonglongask_part(int i){ return part[i] + lazy[i] * len; } inlinelonglongask(int l, int r){ longlong res = 0; while (l % len != 1) res += ask_one(l++); while (r % len != 0) res += ask_one(r--); for (int i = get_id(l); i <= get_id(r); i++) res += ask_part(i); return res; }
vector<longlong> vb[325]; int bel[maxn], l[325], r[325]; longlong arr[maxn], tag[325]; int n, len;
voidreset(int x){ vb[x].clear(); for (int i = l[x]; i <= r[x]; i++) { vb[x].push_back(arr[i]); } sort(vb[x].begin(), vb[x].end()); }
intcal(int x, int v){ v -= tag[x]; auto pos = lower_bound(vb[x].begin(), vb[x].end(), v); return pos - vb[x].begin(); }
intmain(){ scanf("%d", &n); len = sqrt(n); memset(l, 0x3f, sizeof l); for (int i = 1; i <= n; i++) { scanf("%lld", arr + i); bel[i] = (i - 1) / len + 1; l[bel[i]] = min(l[bel[i]], i); r[bel[i]] = max(r[bel[i]], i); vb[bel[i]].push_back(arr[i]); } for (int i = 1; i <= bel[n]; i++) sort(vb[i].begin(), vb[i].end()); for (int i = 1; i <= n; i++) { int op, a, b; longlong c; scanf("%d %d %d %lld", &op, &a, &b, &c); int ba = bel[a], bb = bel[b]; if (op == 0) { for (int i = a; i <= min(r[ba], b); i++) arr[i] += c; reset(ba); if (ba != bb) { for (int i = l[bb]; i <= b; i++) arr[i] += c; reset(bb); } for (int i = ba + 1; i < bb; i++) tag[i] += c; } else { c = c * c; int ans = 0; for (int i = a; i <= min(r[ba], b); i++) ans += (arr[i] + tag[ba]) < c; if (ba != bb) for (int i = l[bb]; i <= b; i++) ans += (arr[i] + tag[bb]) < c; for (int i = ba + 1; i < bb; i++) ans += cal(i, c); printf("%d\n", ans); } } return0; }