2022年5月17日
摘要: 用途:区间增加,区间查询 扩展: “永久性标记” 用途:二维线段树和可持久化线段树难以下传标记的情况下有所应用 局限性非常大,对线段树维护的信息和标记的性质有特殊要求。 阅读全文
posted @ 2022-05-17 20:50 我疯故我在 阅读(131) 评论(0) 推荐(0)
  2022年5月15日
摘要: 当数据范围较大需要离散化,因此需要排序,所以这种情况下不如直接用归并排序。 #include<bits/stdc++.h> using namespace std; const int N=5e5+5; int n; int a[N],b[N]; int c[N]; int ask(int x) { 阅读全文
posted @ 2022-05-15 09:21 我疯故我在 阅读(35) 评论(0) 推荐(0)
  2022年5月14日
摘要: 模板一(单点操作): #include<bits/stdc++.h> using namespace std; const int N=5e5+5; int n,m; int a[N]; int c[N]; void add(int x,int y) { for(; x<=n; x+=x&-x) c 阅读全文
posted @ 2022-05-14 18:02 我疯故我在 阅读(34) 评论(0) 推荐(0)
  2022年5月10日
摘要: 如:从1开始 bfs 1 queue<int> q; 2 q.push(1); 3 c[1]=1; 4 v[1]=1; 5 while(q.size()) { 6 int x=q.front(); 7 q.pop(); 8 for(int i=head[x]; i; i=nxt[i]) { 9 in 阅读全文
posted @ 2022-05-10 20:29 我疯故我在 阅读(58) 评论(0) 推荐(0)
  2022年4月22日
摘要: 归并排序O(nlong) 1 #include<bits/stdc++.h> 2 #define N 100010 3 using namespace std; 4 5 int n; 6 int a[N],tmp[N]; 7 void merge_sort(int l,int r) { 8 if(l 阅读全文
posted @ 2022-04-22 19:12 我疯故我在 阅读(14) 评论(0) 推荐(0)
摘要: 快速排序O(nlong) 1 #include<bits/stdc++.h> 2 #define N 100010 3 using namespace std; 4 5 int n; 6 int a[N]; 7 void qsort(int l,int r) { 8 if(l>=r) return; 阅读全文
posted @ 2022-04-22 19:06 我疯故我在 阅读(36) 评论(0) 推荐(0)
  2022年4月18日
摘要: 1 struct rec { 2 int a, b; // 两个变量,其中a>=b 3 int val, cnt; // 未来估价val,当前次数cnt 4 rec() {} 5 rec(int a_, int b_, int val_, int cnt_) { 6 a = a_, b = b_, 阅读全文
posted @ 2022-04-18 00:08 我疯故我在 阅读(97) 评论(0) 推荐(0)
摘要: 例如:while(ans<=15&&!dfs(0)) ans++; 先判断是否到达了最多步骤的限制,再dfs,防止无效的dfs,如限制15步,如果交换ans<=15和dfs的顺序,则会dfs(16),增加无效的时间。 阅读全文
posted @ 2022-04-18 00:06 我疯故我在 阅读(37) 评论(0) 推荐(0)
  2022年4月16日
摘要: 例如:平面上有n个中转站,n个气井,一一匹对,求n对的哈曼顿距离。 有中转站a,b,气井c,d |xa-xc|+|ya-yc|+|xc-xd|+|yc-yd| 贪心:把所有的中转站,气井x坐标相加,相减取绝对值,y坐标同理 阅读全文
posted @ 2022-04-16 19:13 我疯故我在 阅读(36) 评论(0) 推荐(0)
  2022年4月15日
摘要: 当n为偶数时,n xor 1等于n+1; 当n为奇数时,n xor 1等于n-1。 “0与1”,“2与3”···构成“成对变换”。 i为奇数时,i&1等于1; i为偶数时,i&1等于0。 阅读全文
posted @ 2022-04-15 22:00 我疯故我在 阅读(125) 评论(0) 推荐(0)