随笔分类 - 洛谷
题解
摘要:题目链接 感觉比普通平衡树易懂 代码: #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 7; struct Node{ int p, s[2], mark; int v, tag, size; void init(in
阅读全文
摘要:题目链接 题目要求:插入数据,删除数据,查询数的排名,查询排名为x的 数,找前驱,找后继 旋转操作,左旋和右旋,旋转 ,旋转操作一定要符合先序遍历前后一致 点击查看代码 void rotate(int x){ int y = tr[x].p, z = tr[y].p; int k = tr[y]
阅读全文
摘要:P1533 可怜的狗狗 可持久化线段树的板子题目 离散化(build); 查找(find); #include<bits/stdc++.h> using namespace std; const int N = 3e5 + 7; int a[N], hs[N]; int rt[N], tl[N <<
阅读全文
摘要:P1352 题目的dfs函数与骑士🔗类似,所以去写了下 代码: #include<bits/stdc++.h> using namespace std; const int N = 6e4 + 7; int f[N][2], a[N], in[N]; int head[N], tot; struc
阅读全文
摘要:P2607 当时写题目时的两个坑 有向边的指向是从to->i;如果建边写成addedge(i, to)是不能生成树形结构的(因为讨厌to的骑士可能不止i,会产生一个节点存在多条入边的情况)! 题目没有说明骑士的边构成连通图,所以他们的连通块不一定只有一个(即环可能不止一个)! 代码: #includ
阅读全文
摘要:P1972 [SDOI2009] HH的项链 树状数组题解 将全部输入排序,进行离散化 #include<bits/stdc++.h> using namespace std; #define rint register int const int N = 1e6 + 7; int a[N], tr
阅读全文
摘要:离散化,线段树 #include using namespace std; const int N = 1e5 + 7; int a[N], tree[N > 1; if(x > 1; if(tree[i = m) return query(m, i << 1, l, mid); else retu
阅读全文
摘要:简单的一个分块处理:优雅的暴力枚举 #include<bits/stdc++.h>using namespace std; typedef long long ll;const int N = 2e4 + 7; int st[N];struct Block { int l, r; ll sum, m
阅读全文
摘要:###先用结构体实现了下,发现写错了(只有20分),后面直接用的数组了 #include<bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int a[N], hs[N], rt[N], cnt; struct Node{ int
阅读全文
摘要:线段树的区间修改的修改版 #include<bits/stdc++.h>using namespace std;const int N = 2e5 + 7;int tree[N * 4], mark[N * 4];char str[N]; void push(int l, int r, int i)
阅读全文
摘要:最大生成树,暴力加贪心; #include<bits/stdc++.h>using namespace std;typedef unsigned long long ull;const int N = 2007;ull id[N];int f[N];struct Node{ int i, j; ul
阅读全文
摘要:简简单单的并查集,再加上模拟合并找值 #include<bits/stdc++.h>using namespace std;const int N = 2e5 + 7;int f1[N], f2[N];int u1[N], u2[N], v1[N], v2[N];int ans1[N], ans2[
阅读全文
摘要:感觉可以用tarjan,但奈何弱小的我并没有学过QAQ; 这题的坑就在排序上面 #include<bits/stdc++.h>using namespace std;const int N = 1e6 + 7;struct Edge{ int u, v;}a[N];int f[N];bool cmp
阅读全文
摘要:简简单单的一个并查集 #include<bits/stdc++.h>using namespace std;const int N = 1e6 + 7;int u[N], v[N], f[1010];int find (int x) { return f[x] == x ? x : f[x] = f
阅读全文
摘要:哎呦喂!!看错题目啦!!还以为要用最短路, 就写了个dijkstra,呜呜呜,我就说怎么不对, 呜呜呜QAQ!!! #include<bits/stdc++.h>using namespace std; const int N = 1e4 + 7; int f[N];struct Edge{ int
阅读全文
摘要:最小生成树的板子; 使得连通块的数量减小到k即可! 数据有点水(printf("No Answer");根本没用到QAQ)。 #include<bits/stdc++.h>using namespace std;const int N = 1e3 + 7;const int M = 1e4 + 7;
阅读全文
摘要:#include<bits/stdc++.h>using namespace std;const int N = 1e5 + 7;struct Node{ int bn, ed, t;}a[N];int f[N];int find(int x){ return x == f[x] ? x : f[x
阅读全文
摘要:区间查询加单点修改 这个题目写了很久,然后写了一遍后是错的,但是我感觉我的逻辑是没有问题的; 后来又写了一遍,发现还是错了;就放在那儿了; 今天写的时候,终于把错误找出来了: change_tree中的return条件有问题(l == p); 是错的,应改为:(l == r)!!! #include
阅读全文
摘要:搞不懂为啥这样写有问题 不就是线段树的板子吗!!! 为啥会有问题啊QAQ!!! #include<bits/stdc++.h>using namespace std; typedef long long ll; const int N = 2e5 + 7; ll a[N]; struct Tree{
阅读全文
摘要:水题,线段树板子(单点修改和区间和) #include<bits/stdc++.h>using namespace std; typedef unsigned long long ull; const int N = 1e5 + 7; ull a[N], tree[N * 4]; void chan
阅读全文