inlinevoidchange(int node, int l, int r, int L, int R, int k) { if (L >= l && R <= r) { if (st[node].cnt) { if (L == R) { if (st[node].sum1 < k) { st[node].sum2 = k - st[node].sum1; st[node].sum1 = st[node].cnt = 0; st[node].minn = 1e18; } else { st[node].minn = st[node].sum1 = st[node].sum1 - k; } } else { if (st[node].minn < k) { down(node, L, R); int mid = (L + R) >> 1; change(node << 1, l, r, L, mid, k); change(node << 1 | 1, l, r, mid + 1, R, k); st[node] = up(st[node << 1], st[node << 1 | 1]); } else { st[node].lazy3 += k; st[node].minn -= k; st[node].sum1 -= 1ll * k * st[node].cnt; st[node].lazy1 = k - st[node].lazy1; st[node].lazy2 *= -1; st[node].sum2 = 1ll * k * (R - L + 1 - st[node].cnt) - st[node].sum2; } } } else { st[node].lazy1 = k - st[node].lazy1; st[node].lazy2 *= -1; st[node].sum2 = 1ll * k * (R - L + 1) - st[node].sum2; } // cout<<L<<" "<<R<<" "<<st[node].sum1<<" "<<st[node].sum2<<endl; return; } down(node, L, R); int mid = (L + R) >> 1; if (l <= mid) change(node << 1, l, r, L, mid, k); if (r > mid) change(node << 1 | 1, l, r, mid + 1, R, k); st[node] = up(st[node << 1], st[node << 1 | 1]); return; }
inline Tree query(int node, int l, int r, int L, int R) { if (L >= l && R <= r) return st[node]; down(node, L, R); int mid = (L + R) >> 1; if (r <= mid) returnquery(node << 1, l, r, L, mid); if (l > mid) returnquery(node << 1 | 1, l, r, mid + 1, R); returnup(query(node << 1, l, r, L, mid), query(node << 1 | 1, l, r, mid + 1, R)); }
intmain() { ios::sync_with_stdio(false); cin >> T; while (T--) { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; build(1, 1, n); for (int i = 1; i <= m; i++) { int opt; cin >> opt; if (opt == 1) { int l, r, x; cin >> l >> r >> x; change(1, l, r, 1, n, x); } else { int l, r; cin >> l >> r; Tree ans = query(1, l, r, 1, n); cout << ans.sum1 + ans.sum2 << '\n'; } } } return0; }
constint MOD = 666623333, N = 1e6 + 5; int T = 1; char s[N];
voidsolve() { scanf("%s", s + 1); int n = strlen(s + 1);
vector<pair<char, int>> v; v.push_back({s[1], 1}); for (int i = 2; i <= n; i++) { if (s[i] == v.back().first) ++v.back().second; else v.push_back({s[i], 1}); } int ans = 0; for (auto [x, y] : v) ans += y - 1; cout << ans << endl; }
signedmain(){ scanf("%d", &T); while (T--) { solve(); } return0; }
voidsolve() { int n, Z; scanf("%d%d", &n, &Z); if (n * Z / 25 % 4) { puts("error"); return; } else { for (int i = 0; i < n; i++) scanf("%s", a[i]); int rate = Z / 25; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { int xl = i * rate, xr = xl + rate; int yl = j * rate, yr = yl + rate; char w = a[i][j]; for (int A = xl; A < xr; A++) for (int B = yl; B < yr; B++) b[A][B] = w; } int m = n * rate; for (int i = 0; i < m; i += 4) for (int j = 0; j < m; j += 4) { char w = b[i][j]; for (int A = i; A < i + 4; A++) for (int B = j; B < j + 4; B++) if (b[A][B] != w) { puts("error"); return; } } for (int i = 0; i < m; i += 4) { for (int j = 0; j < m; j += 4) putchar(b[i][j]); puts(""); } } }
signedmain(){ scanf("%d", &T); while (T--) { solve(); } return0; }
inlinevoidup(int &a, int b) { a = (a + b < MOD) ? a + b : a + b - MOD; }
voidsolve() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b + 1, b + n + 1); int m = 0; for (int i = 1; i <= n; i++) if (i == 1 || b[i] > b[i - 1]) b[++m] = b[i]; for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + m + 1, a[i]) - b; sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) f[i] = 1; cout << m << endl; for (int i = 2; i <= n; i++) { sum = ans = 0; for (int j = a[i - 1]; j < a[i]; j++) up(sum, f[j]); for (int j = a[i]; j <= m; j++) { up(sum, f[j]); f[j] = sum; up(ans, sum); } cout << ans << endl; } }
structZ { int a, b; intoperator<(Z o) const { return a + b > o.a + o.b; } }; Z z[100001];
intmain() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &z[i].a, &z[i].b); std::sort(z, z + n); longlong sum = 0; for (int i = 0; i < n; i++) { if (i & 1) sum -= z[i].b; else sum += z[i].a; } printf("%lld\n", sum); } }