主席树有关的一些题目(持续更新)

主席树

模板

P3919 【模板】可持久化线段树 1(可持久化数组)

#include <bits/stdc++.h>using namespace std;const int N = 1e6 + 10;int root[N], n, m;int ls[N * 25], rs[N * 25], value[N * 25], tot;void build(int &rt, int l, int r) {rt = ++tot;if (l == r) {scanf("%d", &value[rt]);return ;}int mid = l + r >> 1;build(ls[rt], l, mid);build(rs[rt], mid + 1, r);
}void update(int &rt, int pre, int l, int r, int x, int v) {rt = ++tot, ls[rt] = ls[pre], rs[rt] = rs[pre], value[rt] = value[pre];if (l == r) {value[rt] = v;return ;}int mid = l + r >> 1;if (x <= mid) {update(ls[rt], ls[pre], l, mid, x, v);}else {update(rs[rt], rs[pre], mid + 1, r, x, v);}
}int query(int rt, int l, int r, int x) {if (l == r) {return value[rt];}int mid = l + r >> 1;if (x <= mid) {return query(ls[rt], l, mid, x);}else {return query(rs[rt], mid + 1, r, x);}
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);scanf("%d %d", &n, &m);build(root[0], 1, n);for (int i = 1; i <= m; i++) {int pre, op, v, x;scanf("%d %d %d", &pre, &op, &x);if (op == 1) {scanf("%d", &v);update(root[i], root[pre], 1, n, x, v);}else {printf("%d\n", query(root[pre], 1, n, x));root[i] = root[pre];}}return 0;
}

P3834 【模板】可持久化线段树 2(主席树)

#include <bits/stdc++.h>using namespace std;const int N = 2e5 + 10;int a[N], b[N], root[N], n, m;int ls[N * 20], rs[N * 20], val[N * 20], tot;void update(int &rt, int pre, int l, int r, int x, int value) {rt = ++tot, ls[rt] = ls[pre], rs[rt] = rs[pre], val[rt] = val[pre] + 1;if (l == r) {return ;}int mid = l + r >> 1;if (x <= mid) {update(ls[rt], ls[pre], l, mid, x, value);}else {update(rs[rt], rs[pre], mid + 1, r, x, value);}
}int query(int rtl, int rtr, int l, int r, int k) {if (l == r) {return l;}int sum = val[ls[rtr]] - val[ls[rtl]], mid = l + r >> 1;if (sum >= k) {return query(ls[rtl], ls[rtr], l, mid, k);}else {return query(rs[rtl], rs[rtr], mid + 1, r, k - sum);}
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);scanf("%d %d", &n, &m);for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);b[i] = a[i];}sort(b + 1, b + 1 + n);int n1 = unique(b + 1, b + 1 + n) - (b + 1);for (int i = 1; i <= n; i++) {int p = lower_bound(b + 1, b + 1 + n1, a[i]) - b;update(root[i], root[i - 1], 1, n1, p, 1);}for (int i = 1; i <= m; i++) {int l, r, k;scanf("%d %d %d", &l, &r, &k);printf("%d\n", b[query(root[l - 1], root[r], 1, n1, k)]);}return 0;
}

P2048 [NOI2010] 超级钢琴

#include <bits/stdc++.h>using namespace std;typedef long long ll;struct Res {int value, id, k;Res(int _value = 0, int _id = 0, int _k = 0) : value(_value), id(_id), k(_k) {}bool operator < (const Res &t) const {return value < t.value;}
};const int N = 5e5 + 10;int a[N], b[N], root[N], n, k, L, R;int ls[N << 6], rs[N << 6], val[N << 6], tot;void update(int &rt, int pre, int l, int r, int x) {rt = ++tot, ls[rt] = ls[pre], rs[rt] = rs[pre], val[rt] = val[pre] + 1;if (l == r) {return ;}int mid = l + r >> 1;if (x <= mid) {update(ls[rt], ls[pre], l, mid, x);}else {update(rs[rt], rs[pre], mid + 1, r, x);}
}int query(int rtl, int rtr, int l, int r, int k) {if (l == r) {return l;}int sum = val[ls[rtr]] - val[ls[rtl]], mid = l + r >> 1;if (sum >= k) {return query(ls[rtl], ls[rtr], l, mid, k);}else {return query(rs[rtl], rs[rtr], mid + 1, r, k - sum);}
}priority_queue<Res> q;int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);scanf("%d %d %d %d", &n, &k, &L, &R);n += 1;for (int i = 2; i <= n; i++) {scanf("%d", &a[i]);a[i] += a[i - 1];b[i] = a[i];}sort(b + 1, b + 1 + n);int n1 = unique(b + 1, b + 1 + n) - (b + 1);for (int i = 1; i <= n; i++) {int p = lower_bound(b + 1, b + 1 + n1, a[i]) - b;update(root[i], root[i - 1], 1, n1, p);}for (int i = L + 1; i <= n; i++) {int l = max(1, i - R), r = i - L;int cur = a[i] - b[query(root[l - 1], root[r], 1, n1, 1)];q.push(Res(cur, i, 1));}ll ans = 0;for (int i = 1; i <= k; i++) {auto it = q.top();q.pop();ans += it.value;if (min(R - L + 1, it.id - L) == it.k) {continue;}int l = max(1, it.id - R), r = it.id - L;it.k++;int cur = a[it.id] - b[query(root[l - 1], root[r], 1, n1, it.k)];q.push(Res(cur, it.id, it.k));}printf("%lld\n", ans);return 0;
}

P2633 Count on a tree

主席树像是一种前缀和的数据结构,所以查询树上两点的第kkk大,可以通过询问sz[u]+sz[v]−sz[lca(u,v)]−sz[fa[lca(u,v)]]sz[u] + sz[v] - sz[lca(u, v)] - sz[fa[lca(u, v)]]sz[u]+sz[v]sz[lca(u,v)]sz[fa[lca(u,v)]]区间。

#include <bits/stdc++.h>using namespace std;const int N = 1e5 + 10;int head[N], to[N << 1], nex[N << 1], cnt = 1;int value[N], a[N], root[N], n, m, n1;int son[N], sz[N], fa[N], dep[N], top[N];int ls[N * 20], rs[N * 20], sum[N * 20], num;void add(int x, int y) {to[cnt] = y;nex[cnt] = head[x];head[x] = cnt++;
}void update(int &rt, int pre, int l, int r, int x) {rt = ++num, ls[rt] = ls[pre], rs[rt] = rs[pre], sum[rt] = sum[pre] + 1;if (l == r) {return ;}int mid = l + r >> 1;if (x <= mid) {update(ls[rt], ls[pre], l, mid, x);}else {update(rs[rt], rs[pre], mid + 1, r, x);}
}void dfs1(int rt, int f) {fa[rt] = f, dep[rt] = dep[f] + 1, sz[rt] = 1;int p = lower_bound(a + 1, a + 1 + n1, value[rt]) - a;update(root[rt], root[f], 1, n1, p);for (int i = head[rt]; i; i = nex[i]) {if (to[i] == f) {continue;}dfs1(to[i], rt);sz[rt] += sz[to[i]];if (!son[rt] || sz[son[rt]] < sz[to[i]]) {son[rt] = to[i];}}
}void dfs2(int rt, int tp) {top[rt] = tp;if (!son[rt]) {return ;}dfs2(son[rt], tp);for (int i = head[rt]; i; i = nex[i]) {if (to[i] == fa[rt] || to[i] == son[rt]) {continue;}dfs2(to[i], to[i]);}
}int lca(int x, int y) {while (top[x] != top[y]) {if (dep[top[x]] < dep[top[y]]) {swap(x, y);}x = fa[top[x]];}return dep[x] < dep[y] ? x : y;
}int query(int x, int y, int f, int ff, int l, int r, int k) {if (l == r) {return l;}int ans = sum[ls[x]] + sum[ls[y]] - sum[ls[f]] - sum[ls[ff]], mid = l + r >> 1;if (ans >= k) {return query(ls[x], ls[y], ls[f], ls[ff], l, mid, k);}else {return query(rs[x], rs[y], rs[f], rs[ff], mid + 1, r, k - ans);}
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);scanf("%d %d", &n, &m);for (int i = 1; i <= n; i++) {scanf("%d", &value[i]);a[i] = value[i];}for (int i = 1; i < n; i++) {int x, y;scanf("%d %d", &x, &y);add(x, y);add(y, x);}sort(a + 1, a + 1 + n);n1 = unique(a + 1, a + 1 + n) - (a + 1);dfs1(1, 0);dfs2(1, 1);int last = 0;for (int i = 1; i <= m; i++) {int u, v, k;scanf("%d %d %d", &u, &v, &k);u ^= last;int f = lca(u, v), ff = fa[f];last = query(root[u], root[v], root[f], root[ff], 1, n1, k);last = a[last];printf("%d\n", last);}return 0;
}

#1901. Zju2112 Dynamic Rankings

#include <bits/stdc++.h>using namespace std;const int N = 1e4 + 10, maxn = 1000000000;int a[N], n, m;int root[N], ls[N << 8], rs[N << 8], sum[N << 8], num;int A[N], B[N], cnt1, cnt2;inline int lowbit(int x) {return x & (-x);
}void update(int &rt, int l, int r, int x, int v) {if (!rt) {rt = ++num;}sum[rt] += v;if (l == r) {return ;}int mid = l + r >> 1;if (x <= mid) {update(ls[rt], l, mid, x, v);}else {update(rs[rt], mid + 1, r, x, v);}
}int query(int l, int r, int k) {if (l == r) {return l;}int cur = 0, mid = l + r >> 1;for (int i = 1; i <= cnt1; i++) {cur -= sum[ls[A[i]]];}for (int i = 1; i <= cnt2; i++) {cur += sum[ls[B[i]]];}if (cur >= k) {for (int i = 1; i <= cnt1; i++) {A[i] = ls[A[i]];}for (int i = 1; i <= cnt2; i++) {B[i] = ls[B[i]];}return query(l, mid, k);}else {for (int i = 1; i <= cnt1; i++) {A[i] = rs[A[i]];}for (int i = 1; i <= cnt2; i++) {B[i] = rs[B[i]];}return query(mid + 1, r, k - cur);}
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);scanf("%d %d", &n, &m);for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);for (int j = i; j <= n; j += lowbit(j)) {update(root[j], 0, maxn, a[i], 1);}}for (int i = 1; i <= m; i++) {char op[2];int u, v, k;scanf("%s %d %d", op, &u, &v);if (op[0] == 'Q') {scanf("%d", &k);cnt1 = cnt2 = 0;for (int i = u - 1; i; i -= lowbit(i)) {A[++cnt1] = root[i];}for (int i = v; i; i -= lowbit(i)) {B[++cnt2] = root[i];}printf("%d\n", query(0, maxn, k));}else {for (int i = u; i <= n; i += lowbit(i)) {update(root[i], 0, maxn, a[u], -1);}a[u] = v;for (int i = u; i <= n; i += lowbit(i)) {update(root[i], 0, maxn, a[u], 1);}}}return 0;
}

P4175 [CTSC2008]网络管理

#include <bits/stdc++.h>using namespace std;const int N = 8e4 + 10, maxn = 100000000;int a[N], n, m;int head[N], to[N << 1], nex[N << 1], cnt = 1;int son[N], sz[N], l[N], r[N], dep[N], top[N], fa[N], tot;int root[N], sum[N << 8], ls[N << 8], rs[N << 8], num;int A[N], B[N], cnt1, cnt2;inline int lowbit(int x) {return x & (-x);
}inline void add(int x, int y) {to[cnt] = y;nex[cnt] = head[x];head[x] = cnt++;
}void update(int &rt, int l, int r, int x, int v) {if (!rt) {rt = ++num;}sum[rt] += v;if (l == r) {return ;}int mid = l + r >> 1;if (x <= mid) {update(ls[rt], l, mid, x, v);}else {update(rs[rt], mid + 1, r, x, v);}
}void dfs1(int rt, int f) {fa[rt] = f, l[rt] = ++tot, sz[rt] = 1, dep[rt] = dep[f] + 1;for (int i = l[rt]; i <= n; i += lowbit(i)) {update(root[i], 0, maxn, a[rt], 1);}for (int i = head[rt]; i; i = nex[i]) {if (to[i] == f) {continue;}dfs1(to[i], rt);sz[rt] += sz[to[i]];if (!son[rt] || sz[son[rt]] < sz[to[i]]) {son[rt] = to[i];}}r[rt] = tot;for (int i = r[rt] + 1; i <= n; i += lowbit(i)) {update(root[i], 0, maxn, a[rt], -1);}
}void dfs2(int rt, int tp) {top[rt] = tp;if (!son[rt]) {return ;}dfs2(son[rt], tp);for (int i = head[rt]; i; i = nex[i]) {if (to[i] == fa[rt] || to[i] == son[rt]) {continue;}dfs2(to[i], to[i]);}
}int lca(int x, int y) {while (top[x] != top[y]) {if (dep[top[x]] < dep[top[y]]) {swap(x, y);}x = fa[top[x]];}return dep[x] < dep[y] ? x : y;
}int query(int l, int r, int k) {if (l == r) {return l;}int cur = 0, mid = l + r >> 1;for (int i = 1; i <= cnt1; i++) {cur += sum[ls[A[i]]];}for (int i = 1; i <= cnt2; i++) {cur -= sum[ls[B[i]]];}if (cur >= k) {for (int i = 1; i <= cnt1; i++) {A[i] = ls[A[i]];}for (int i = 1; i <= cnt2; i++) {B[i] = ls[B[i]];}return query(l, mid, k);}else {for (int i = 1; i <= cnt1; i++) {A[i] = rs[A[i]];}for (int i = 1; i <= cnt2; i++) {B[i] = rs[B[i]];}return query(mid + 1, r, k - cur);}
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);scanf("%d %d", &n, &m);for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);}for (int i = 1; i < n; i++) {int x, y;scanf("%d %d", &x, &y);add(x, y);add(y, x);}dfs1(1, 0);dfs2(1, 1);for (int i = 1; i <= m; i++) {int k, u, v;scanf("%d %d %d", &k, &u, &v);if (!k) {for (int i = l[u]; i <= n; i += lowbit(i)) {update(root[i], 0, maxn, a[u], -1);}for (int i = r[u] + 1; i <= n; i += lowbit(i)) {update(root[i], 0, maxn, a[u], 1);}a[u] = v;for (int i = l[u]; i <= n; i += lowbit(i)) {update(root[i], 0, maxn, a[u], 1);}for (int i = r[u] + 1; i <= n; i += lowbit(i)) {update(root[i], 0, maxn, a[u], -1);}}else {int f = lca(u, v), ff = fa[f], total = dep[u] + dep[v] - dep[f] - dep[ff];if (total < k) {puts("invalid request!");}else {cnt1 = cnt2 = 0;for (int i = l[u]; i; i -= lowbit(i)) {A[++cnt1] = root[i];}for (int i = l[v]; i; i -= lowbit(i)) {A[++cnt1] = root[i];}for (int i = l[f]; i; i -= lowbit(i)) {B[++cnt2] = root[i];}for (int i = l[ff]; i; i -= lowbit(i)) {B[++cnt2] = root[i];}k = total - k + 1;printf("%d\n", query(0, maxn, k));}}}return 0;
}

#279. [SYZOI Round1] 滑稽♂树

#include <bits/stdc++.h>using namespace std;const int N = 3e4 + 10, maxn = 10000;int head[N], to[N << 1], nex[N << 1], cnt = 1;int l[N], r[N], tot;int a[N], n, m;int root[N], ls[N << 8], rs[N << 8], sum[N << 8], num;int A[N], B[N], cnt1, cnt2;inline void add(int x, int y) {to[cnt] = y;nex[cnt] = head[x];head[x] = cnt++;
}inline int lowbit(int x) {return x & (-x);
}void update(int &rt, int l, int r, int x, int v) {if (!rt) {rt = ++num;}sum[rt] += v;if (l == r) {return; }int mid = l + r >> 1;if (x <= mid) {update(ls[rt], l, mid, x, v);}else {update(rs[rt], mid + 1, r, x, v);}
}void dfs(int rt, int fa) {l[rt] = ++tot;for (int i = l[rt]; i <= n; i += lowbit(i)) {update(root[i], 1, maxn, a[rt], 1);}for (int i = head[rt]; i; i = nex[i]) {if (to[i] == fa) {continue;}dfs(to[i], rt);}r[rt] = tot;
}int query1(int l, int r, int k) {if (l == r) {return l;}int cur = 0, mid = l + r >> 1;for (int i = 1; i <= cnt1; i++) {cur -= sum[ls[A[i]]];}for (int i = 1; i <= cnt2; i++) {cur += sum[ls[B[i]]];}if (cur >= k) {for (int i = 1; i <= cnt1; i++) {A[i] = ls[A[i]];}for (int i = 1; i <= cnt2; i++) {B[i] = ls[B[i]];}return query1(l, mid, k);}else {for (int i = 1; i <= cnt1; i++) {A[i] = rs[A[i]];}for (int i = 1; i <= cnt2; i++) {B[i] = rs[B[i]];}return query1(mid + 1, r, k - cur);}
}int query2(int l, int r, int L, int R) {if (l >= L && r <= R) {int res = 0;for (int i = 1; i <= cnt1; i++) {res -= sum[A[i]];}for (int i = 1; i <= cnt2; i++) {res += sum[B[i]];}return res;}int mid = l + r >> 1, res = 0;int A1[100], B1[100];if (L <= mid) {for (int i = 1; i <= cnt1; i++) {A1[i] = A[i];A[i] = ls[A[i]];}for (int i = 1; i <= cnt2; i++) {B1[i] = B[i];B[i] = ls[B[i]];}res += query2(l, mid, L, R);for (int i = 1; i <= cnt1; i++) {A[i] = A1[i];}for (int i = 1; i <= cnt2; i++) {B[i] = B1[i];}}if (R > mid) {for (int i = 1; i <= cnt1; i++) {A1[i] = A[i];A[i] = rs[A[i]];}for (int i = 1; i <= cnt2; i++) {B1[i] = B[i];B[i] = rs[B[i]];}res += query2(mid + 1, r, L, R);for (int i = 1; i <= cnt1; i++) {A[i] = A1[i];}for (int i = 1; i <= cnt2; i++) {B[i] = B1[i];}}return res;
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);scanf("%d", &n);for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);}for (int i = 1; i < n; i++) {int x, y;scanf("%d %d", &x, &y);add(x, y);add(y, x);}dfs(1, 0);scanf("%d", &m);for (int i = 1; i <= m; i++) {int op, u, x, y;scanf("%d %d %d", &op, &u, &x);if (op == 1) {cnt1 = cnt2 = 0;for (int i = l[u] - 1; i ; i -= lowbit(i)) {A[++cnt1] = root[i];}for (int i = r[u]; i; i -= lowbit(i)) {B[++cnt2] = root[i];}printf("%d\n", query1(1, maxn, x));}else if (op == 2) {scanf("%d", &y);cnt1 = cnt2 = 0;for (int i = l[u] - 1; i ; i -= lowbit(i)) {A[++cnt1] = root[i];}for (int i = r[u]; i; i -= lowbit(i)) {B[++cnt2] = root[i];}printf("%d\n", query2(1, maxn, x, y));}else {for (int i = l[u]; i <= n; i += lowbit(i)) {update(root[i], 1, maxn, a[u], -1);}a[u] = x;for (int i = l[u]; i <= n; i += lowbit(i)) {update(root[i], 1, maxn, a[u], 1);}}}return 0;
}

Sequence II

题目大意是有mmm次询问,每次询问一段区间[l,r][l, r][l,r],从左到右,如果这个数是在这个区间第一次出现,则记录下其下标,

我们会得到一个新的数组,要求这个数组的中位数是什么。

考虑使用主席树来写,我们倒序插入这些数的信息并记录下这个数上一次是出现在哪,对于每个点我们将其下标在主席树中+1+1+1,然后对于上一次出现的下标,在主席树中−1-11,所以我们直接在第lll棵主席树中查询区间[l,r][l, r][l,r]的权值即是这个区间的不同数字个数,在这个区间里,对于相同的数字,我们只会认定最右边的那个一个数字,所以重复的数字会消除。

然后再在第lll棵主席树中查找第kkk大即可得到答案了。

#include <bits/stdc++.h>using namespace std;const int N = 2e5 + 10;int a[N], pos[N], n, m, ans;int root[N], ls[N << 6], rs[N << 6], sum[N << 6], num;void update(int &rt, int pre, int l, int r, int x, int v) {rt = ++num, ls[rt] = ls[pre], rs[rt] = rs[pre], sum[rt] = sum[pre] + v;if (l == r) {return ;}int mid = l + r >> 1;if (x <= mid) {update(ls[rt], ls[pre], l, mid, x, v);}else {update(rs[rt], rs[pre], mid + 1, r, x, v);}
}int query_sum(int rt, int l, int r, int L, int R) {if (!rt) {return 0;}if (l >= L && r <= R) {return sum[rt];}int mid = l + r >> 1, ans = 0;if (L <= mid) {ans += query_sum(ls[rt], l, mid, L, R);}if (R > mid) {ans += query_sum(rs[rt], mid + 1, r, L, R);}return ans;
}int query_k(int rt, int l, int r, int k) {if (l == r) {return l;}int cur = sum[ls[rt]], mid = l + r >> 1;if (cur >= k) {return query_k(ls[rt], l, mid, k);}else {return query_k(rs[rt], mid + 1, r, k - cur);}
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int T;scanf("%d", &T);for (int cas = 1; cas <= T; cas++) {printf("Case #%d:", cas);memset(pos, 0, sizeof pos);for (int i = 0; i <= n; i++) {root[i] = 0;}for (int i = 0; i <= num; i++) {ls[i] = rs[i] = sum[i] = 0;}num = ans = 0;scanf("%d %d", &n, &m);for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);}for (int i = n; i >= 1; i--) {update(root[i], root[i + 1], 1, n, i, 1);if (pos[a[i]]) {update(root[i], root[i], 1, n, pos[a[i]], -1);}pos[a[i]] = i;}for (int i = 1; i <= m; i++) {int l, r;scanf("%d %d", &l, &r);l = (l + ans) % n + 1, r = (r + ans) % n + 1;if (l > r) {swap(l, r);}int sum = query_sum(root[l], 1, n, l, r);ans = query_k(root[l], 1, n, sum + 1 >> 1);printf(" %d", ans);}puts("");}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/313923.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

密钥分离,.Net程序猿不再背锅

引言互联网每隔一段时间就会爆出 【某程序猿在代码托管平台上传了公司机密配置信息&#xff0c;导致公司核心数据被黑客获取或修改】&#xff0c; 一茬又一茬背锅侠层出不穷。拯救自我软件工程理论早以加粗字体给出 经典原则&#xff1a;Never store production passwords or o…

Java ASM与Javassit

操作java字节码的工具有两个比较流行&#xff0c;一个是ASM&#xff0c;一个是Javassit 。 ASM &#xff1a;直接操作字节码指令&#xff0c;执行效率高&#xff0c;要是使用者掌握Java类字节码文件格式及指令&#xff0c;对使用者的要求比较高。 Javassit 提供了更高级的API…

Chrome让人失望,是时候转到Firefox或Edge?

我们曾报道过谷歌正在移除 Chrome 的关闭其他选项卡&#xff0c;这引起很多用户的讨论&#xff0c;很多用户表现出对 Chrome 浏览器的失望。而在国外&#xff0c;也有很多人认为谷歌这项修改使 Chrome 变得越来越臃肿。还有前段时间&#xff0c;谷歌在 Chrome 76 中隐藏了 “ht…

ICPC 徐州 H Yuuki and a problem (树状数组套主席树)

Yuuki and a problem 先不管第一问的修改操作&#xff0c;考虑如何达到第二问的查询操作&#xff0c; 题目要我们给出一个区间[l,r][l, r][l,r]中&#xff0c;不能通过权值得到的最小的数字是什么&#xff0c; 假设我们已经可以得到[1,x][1, x][1,x]之间的数了&#xff0c;且…

Java序列化、反序列化

目录 1&#xff1a;什么是序列化、反序列化&#xff1f; 2&#xff1a;序列化的用途&#xff1f; 3&#xff1a;序列化的n种方式 1&#xff1a;什么是序列化、反序列化&#xff1f; 把对象转换为字节序列的过程称为对象的序列化把字节序列转换为对象的过程中称为对象的反序列…

我认真写下9段如翔一般的代码,只为等你来品鉴

溪源 | 长沙.NET技术社区开篇我们总是很容易就能写出满足某个特定功能的代码&#xff0c;却很难写出优雅代码。又最欣赏那些优雅的代码&#xff0c;因为优雅代码更能体现一个开发者的积累。就像写一篇散文&#xff0c;有的就像初学者不得其门而入&#xff0c;遣词造句都非常困难…

P2596 [ZJOI2006]书架(fhq treap)

P2596 [ZJOI2006]书架 我们用fhq treap来完成这一题 对于一个新插入的节点我们取权值为其索引值&#xff0c;其所记录的valuevaluevalue是其当前索引所在位置。 操作一&#xff1a;把索引为valuevaluevalue的点放到平衡树前面&#xff0c;分别别得到三颗子树x,y,zx, y, zx,y…

「标签管理」用数据管理思维去管理你的日常电子化资料、文件、笔记等

最近一时兴起&#xff0c;研究了一些文件管理的方法论和笔记管理类的知识&#xff0c;自己想到一些不错的方法及落地方案&#xff0c;可能对一部分朋友来说&#xff0c;这些方法和工具的落地会有一些共鸣&#xff0c;故简单给大家做一下分享。跨界应用&#xff1a;数据表结构应…

Java之JMS

一&#xff1a;JMS简介   JMS即Java消息服务&#xff08;Java Message Service&#xff09;&#xff0c;是一个Java平台定义的关于面向消息中间件的API&#xff0c;用于在两个应用程序之间&#xff0c;或分布式系统中发送消息&#xff0c;进行异步通信。JMS是一个与具体平台无…

程序员过关斩将--更加优雅的Token认证方式JWT

点击上方“蓝字”带你去看小星星菜菜&#xff0c;上次你讲的cookie和session认证方式&#xff0c;我这次面试果然遇到了结果怎么样&#xff1f;结果面试官问我还有没有更好的方式&#xff1f;看来你又挂了别说了&#xff0c;伤心呀。到底还有没有更好的方式呢&#xff1f;你猜&…

Java之JMX

JMX&#xff0c;即Java Management Extensions&#xff0c;Java管理扩展。是一个为应用程序、设备、系统等植入管理功能的框架。   JMX提供了一种简单、基础的方法&#xff0c;用来管理应用、设置、服务等资源。由于JMX是动态的&#xff0c;你可以使用JMX技术来监控和管理处于…

平衡树(模板 and 题目)记录

平衡树 替罪羊树 #include <bits/stdc.h>using namespace std;const double alpha 0.725; const int N 2e6 10;struct Spgtree {int ls[N], rs[N], val[N], num[N], fac[N], sz[N], sum[N], cnt, root;int top, stk[N];void update(int rt) {fac[rt] fac[ls[rt]] …

[NewLife.XCode]分表分库(百亿级大数据存储)

NewLife.XCode是一个有15年历史的开源数据中间件&#xff0c;支持netcore/net45/net40&#xff0c;由新生命团队(2002~2019)开发完成并维护至今&#xff0c;以下简称XCode。整个系列教程会大量结合示例代码和运行日志来进行深入分析&#xff0c;蕴含多年开发经验于其中&#xf…

Java -- 泛型

1、什么是泛型&#xff1f; 泛型&#xff08;Generics&#xff09;是把类型参数化&#xff0c;运用于类、接口、方法中&#xff0c;在调用时传入具体的类型。 泛型就是参数化类型 适用于多种数据类型执行相同的代码泛型的类型在使用时指定泛型归根到底就是“模板” 优点&…

HDU 6703 array(主席树 + set)

array 给一个全排列&#xff0c;接下来有两种操作&#xff1a; 一、把pospospos位置上的值10,000,00010,000,00010,000,000。 二、查询[1,r][1, r][1,r]区间&#xff0c;没有出现的且≥k\geq k≥k的最小值是多少。 考虑用主席树 set 求解&#xff0c; 先建立一颗主席树&a…

你的技术债还了吗?

什么是技术债&#xff1f;技术债是由沃德坎宁安在1992年提出&#xff0c;指我们在软件架构或代码编写过程中有意无意地做了错误的决策。随着时间的累积&#xff0c;这种错误会越来越多&#xff0c;就像背负了很多债务一样。技术债的危害技术债同财务债一样&#xff0c;是有利息…

拿 C# 搞函数式编程

最近闲下来了&#xff0c;准备出一个 C# 搞 FP 的合集。本合集所有代码均以 C# 8 为示例。可能你说&#xff0c;为什么要这么做呢&#xff1f;回答&#xff1a;为了好玩。另外&#xff0c;意义党们请 gun cu ke&#xff01;C# 有委托&#xff0c;而且有 Func<> 和 Action…

P3250 [HNOI2016]网络(利用堆建线段树 + 树剖)

P3250 [HNOI2016]网络 做法有点神奇&#xff01;&#xff01;&#xff01;利用堆作为节点建立一颗线段树&#xff0c;用堆维护线段树上点的信息。 说说查询操作&#xff0c;我们的目的是要查询&#xff0c;没有经过这个点的事件最大值&#xff0c;考虑如何维护。 我们定义线…

CNCF发布K8s项目历程报告,35k贡献者有你吗?

云原生计算基金会 CNCF 首次发布了 Kubernetes 项目历程报告。Kubernetes 托管于 CNCF&#xff0c;它是目前使用最广泛的容器编排平台&#xff0c;通常被称为“云端 Linux”&#xff0c;CNCF 介绍此报告旨在客观地评估 Kubernetes 项目的状态以及 CNCF 如何影响 Kubernetes 的发…

NUMTRYE - Number Theory (Easy)

NUMTRYE - Number Theory (Easy) Hard 版本就是用 pollard_rho 分解质因子。 f(n)∏(pi2ei11)f(n) \prod(p_i ^{2e_i 1} 1)f(n)∏(pi2ei​1​1)&#xff0c;g(n)∑i1nngcd⁡(n,i)g(n) \sum\limits_{i 1} ^{n} \frac{n}{\gcd(n, i)}g(n)i1∑n​gcd(n,i)n​&#xff0c;pip…