int n = rd(), len = sqrt(n); // n 元素个数 len 块长 for (int i = 0; i < n; ++i) { a[i] = rd(); if (i % len == 0) L[i / len] = i; // L[] 块的左端点 R[i / len] = i; // R[] 块的右端点 }
#define N 50007 #define M 230 ll a[N], tag[M]; int L[M], R[M];
intmain(){ int n = rd(), len = sqrt(n); for (int i = 0; i < n; ++i) { a[i] = rd(); if (i % len == 0) L[i / len] = i; R[i / len] = i; } for (int i = 1; i <= n; ++i) { int op = rd(), l = rd() - 1, r = rd() - 1, c = rd(); int bll = l / len, blr = r / len; if (op) { printf("%lld\n", a[r] + tag[blr]); } else { if (bll == blr) { for (int i = l; i <= r; ++i) a[i] += c; } else { for (int i = l; i <= R[bll]; ++i) a[i] += c; for (int i = L[blr]; i <= r; ++i) a[i] += c; for (int i = bll + 1; i < blr; ++i) tag[i] += c; } } } return0; }
#define N 50007 #define M 230 ll tag[M], a[N]; int L[M], R[M]; vector<ll> v[M];
intmain(){ int n = rd(), len = sqrt(n); for (int i = 0; i < n; ++i) { v[i / len].pb(a[i] = rd()); if (i % len == 0) L[i / len] = i; R[i / len] = i; } for (int i = 0; i <= (n - 1) / len; ++i) sort(v[i].begin(), v[i].end()); for (int q = 1; q <= n; ++q) { int op = rd(), l = rd() - 1, r = rd() - 1; ll c = rd(); int bll = l / len, blr = r / len; if (op) { c *= c; int cnt = 0; if (bll == blr) { for (int i = l; i <= r; ++i) if (a[i] < c - tag[bll]) ++cnt; } else { for (int i = l; i <= R[bll]; ++i) if (a[i] < c - tag[bll]) ++cnt; for (int i = L[blr]; i <= r; ++i) if (a[i] < c - tag[blr]) ++cnt; for (int i = bll + 1; i < blr; ++i) { auto it = lower_bound(v[i].begin(), v[i].end(), c - tag[i]); cnt += it - v[i].begin(); } } printf("%d\n", cnt); } else { if (bll == blr) { for (int i = l; i <= r; ++i) a[i] += c; v[bll].clear(); for (int i = L[bll]; i <= R[bll]; ++i) v[bll].pb(a[i]); sort(v[bll].begin(), v[bll].end()); } else { for (int i = l; i <= R[bll]; ++i) a[i] += c; v[bll].clear(); for (int i = L[bll]; i <= R[bll]; ++i) v[bll].pb(a[i]); sort(v[bll].begin(), v[bll].end()); for (int i = L[blr]; i <= r; ++i) a[i] += c; v[blr].clear(); for (int i = L[blr]; i <= R[blr]; ++i) v[blr].pb(a[i]); sort(v[blr].begin(), v[blr].end()); for (int i = bll + 1; i < blr; ++i) tag[i] += c; } } } return0; }
#define N 100007 #define M 330 ll tag[M], a[N]; int L[M], R[M]; vector<ll> v[M];
intmain(){ int n = rd(), len = sqrt(n); for (int i = 0; i < n; ++i) { v[i / len].pb(a[i] = rd()); if (i % len == 0) L[i / len] = i; R[i / len] = i; } for (int i = 0; i <= (n - 1) / len; ++i) sort(v[i].begin(), v[i].end()); for (int q = 1; q <= n; ++q) { int op = rd(), l = rd() - 1, r = rd() - 1; ll c = rd(); int bll = l / len, blr = r / len; if (op) { ll mx = -1e18; if (bll == blr) { for (int i = l; i <= r; ++i) if (a[i] < c - tag[bll]) mx = max(mx, a[i] + tag[bll]); } else { for (int i = l; i <= R[bll]; ++i) if (a[i] < c - tag[bll]) mx = max(mx, a[i] + tag[bll]); for (int i = L[blr]; i <= r; ++i) if (a[i] < c - tag[blr]) mx = max(mx, a[i] + tag[blr]); for (int i = bll + 1; i < blr; ++i) { auto it = lower_bound(v[i].begin(), v[i].end(), c - tag[i]); if (it != v[i].begin()) mx = max(mx, (*(--it)) + tag[i]); } } printf("%lld\n", mx == -1e18 ? -1 : mx); } else { if (bll == blr) { for (int i = l; i <= r; ++i) a[i] += c; v[bll].clear(); for (int i = L[bll]; i <= R[bll]; ++i) v[bll].pb(a[i]); sort(v[bll].begin(), v[bll].end()); } else { for (int i = l; i <= R[bll]; ++i) a[i] += c; v[bll].clear(); for (int i = L[bll]; i <= R[bll]; ++i) v[bll].pb(a[i]); sort(v[bll].begin(), v[bll].end()); for (int i = L[blr]; i <= r; ++i) a[i] += c; v[blr].clear(); for (int i = L[blr]; i <= R[blr]; ++i) v[blr].pb(a[i]); sort(v[blr].begin(), v[blr].end()); for (int i = bll + 1; i < blr; ++i) tag[i] += c; } } } return0; }
#define N 50007 #define M 230 ll a[N], tag[M], sum[M]; int L[M], R[M];
intmain(){ int n = rd(), len = sqrt(n); for (int i = 0; i < n; ++i) { sum[i / len] += (a[i] = rd()); if (i % len == 0) L[i / len] = i; R[i / len] = i; } for (int q = 1; q <= n; ++q) { int op = rd(), l = rd() - 1, r = rd() - 1; ll c = rd(); int bll = l / len, blr = r / len; if (op) { c++; ll ans = 0; if (bll == blr) { ans = (ans + (r - l + 1) * tag[bll]) % c; for (int i = l; i <= r; ++i) ans = (ans + a[i]) % c; } else { for (int i = l; i <= R[bll]; ++i) ans = (ans + a[i] + tag[bll]) % c; for (int i = L[blr]; i <= r; ++i) ans = (ans + a[i] + tag[blr]) % c; for (int i = bll + 1; i < blr; ++i) ans = (ans + sum[i]) % c; } printf("%lld\n", ans); } else { if (bll == blr) { sum[bll] += c * (r - l + 1); for (int i = l; i <= r; ++i) a[i] += c; } else { for (int i = l; i <= R[bll]; ++i) {sum[bll] += c; a[i] += c;} for (int i = L[blr]; i <= r; ++i) {sum[blr] += c; a[i] += c;} for (int i = bll + 1; i < blr; ++i) {sum[i] += len * c; tag[i] += c;} } } } return0; }