Skip to content

Commit

Permalink
4.7
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Apr 7, 2019
1 parent c8a7d0c commit 12da95d
Show file tree
Hide file tree
Showing 11 changed files with 725 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@
- [x] bzoj4407
- [ ] bzoj2813
- [ ] bzoj4428
- [ ] UOJ450
# 扩展欧几里得
- [ ] LOJ#6440
- [ ] CF868G
Expand Down Expand Up @@ -343,7 +344,7 @@
- [ ] bzoj4514
- [ ] bzoj3532
- [ ] uoj77
- [ ] Codeforces 786E ALT
- [x] Codeforces 786E ALT
# 分块及按大小分类
- [x] LOJ#6277-6285
- [x] bzoj2741
Expand All @@ -366,6 +367,7 @@
- [x] bzoj2989 数列
- [ ] bzoj2961
- [ ] bzoj3236
- [ ] LOJ#3030. 「JOISC 2019 Day1」考试
# 2-SAT
- [ ] LOJ#571. 「LibreOJ Round #11」Misaka Network 与 Accelerator
- [ ] LOJ#2155. 「POI2011 R1」同谋者 Conspiracy
Expand Down
2 changes: 2 additions & 0 deletions Review/NetworkFlows/MaxFlow.tex
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ \subsubsection{优化}

{\bfseries 注意$mf=0$时直接返回不要更新层次标号。}

{\bfseries 为了防止初始0流的情况,需要特判并将$d[S]$置为$+\infty$。}

ISAP算法参考了permui的博客\footnote{ 最大流算法-ISAP - permui
\url{https://www.cnblogs.com/owenyu/p/6852664.html}}。

Expand Down
10 changes: 10 additions & 0 deletions Review/Other/TricksAndIdeas.tex
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ \subsection{MITM}
\lstinputlisting{Source/Source/Search/2324.cpp}
\subsection{倍增}
通过多一个$\lg$预处理跳跃$2^k$步的信息,以达到$\lg$级快速移动的目的。

\subsubsection{倍增优化连边}
有时需要从一个点到树上的一条链连边,那么可以记$P[i][j]$表示从点$i$开始往上$2^j$
层的链对应的节点,然后将其连无用边到子链。这样可以保证每次连边是$O(\lg n)$的。
\subsection{随机化}
对于一些时间复杂度为期望复杂度的算法,需要对数据顺序随机化来避免被卡。

Expand Down Expand Up @@ -493,6 +497,8 @@ \subsection{注意事项/常见转化/思想}
\item 对于整体取反操作,可以同时维护两个方面的信息,取反时直接swap。
\item 对于区间内选取最佳位置问题,可以将询问按照左端点排序,然后从右到左加入每个位置,
使用单调栈维护位置作为答案的区间,二分查询回答询问。
\item 对于复制数据结构的问题,考虑复制的每个元素中待统计信息的占比,修改时大部分的转移
是相同的。
\end{itemize}
\subsection{比赛注意事项}
\subsubsection{Linux/GCC工具}
Expand Down Expand Up @@ -562,6 +568,10 @@ \subsubsection{代码注意事项}
\item set与map的插入与删除操作不影响之前取得的迭代器的有效性。
\item 调试输出时重定向至stderr,即使忘记删掉也可以降低风险。
\item \%c输入时不会跳不可见字符,可以在其前面加空格或者使用\%s
\item 使用strtol/strtod时,要么一次性读入整个文件,要么读完整段后再调用,
直接在缓冲区上搞可能会导致RE与读入错误。
\item 避免出现Undefined behavior导致优化后程序错误。例如有符号整数溢出:要
利用自然溢出特性时强转至unsigned做加法。
\end{itemize}
\subsection{本节注记}
2013年许昊然的国家集训队论文答辩《浅谈数据结构题的几个非经典解法——<Claymore>命题报告》
Expand Down
86 changes: 86 additions & 0 deletions Source/Competition/Multi2019/LOJ3048.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <cstdio>
#include <queue>
namespace IO {
char in[1 << 23];
void init() {
fread(in, 1, sizeof(in), stdin);
}
char getc() {
static char* S = in;
return *S++;
}
}
typedef unsigned int U32;
U32 read() {
U32 res = 0, c;
do
c = IO::getc();
while(c < '0' || c > '9');
while('0' <= c && c <= '9') {
res = res * 10U + c - '0';
c = IO::getc();
}
return res;
}
const int size = 500005, maxd = 31;
struct Node {
int siz, c[2];
} T[size * 80];
int root[size], tcnt = 0;
int modify(int src, U32 x, int d, int op) {
int id = ++tcnt;
T[id] = T[src];
T[id].siz += op;
if(d != -1) {
int& c = T[id].c[(x >> d) & 1];
c = modify(c, x, d - 1, op);
}
return id;
}
U32 query(int id, U32 x, int d) {
if(d == -1)
return 0;
int bx = (x >> d) & 1, nb = bx ^ 1,
c = T[id].c[nb];
if(T[c].siz)
return query(c, x, d - 1) | (1U << d);
return query(T[id].c[bx], x, d - 1);
}
struct Sol {
int u;
U32 val;
Sol(int u, U32 val) : u(u), val(val) {}
bool operator<(const Sol& rhs) const {
return val < rhs.val;
}
};
U32 A[size];
Sol getSol(int u) {
U32 x = A[u - 1];
U32 val = query(root[u], x, maxd);
root[u] = modify(root[u], x ^ val, maxd, -1);
return Sol(u, val);
}
typedef unsigned long long U64;
int main() {
IO::init();
int n = read();
int k = read();
for(int i = 1; i <= n; ++i)
A[i] = A[i - 1] ^ read();
for(int i = n; i >= 1; --i)
root[i] = modify(root[i + 1], A[i], maxd, 1);
std::priority_queue<Sol> heap;
for(int i = 1; i <= n; ++i)
heap.push(getSol(i));
U64 sum = 0;
for(int i = 1; i <= k; ++i) {
sum += heap.top().val;
int u = heap.top().u;
heap.pop();
if(T[root[u]].siz)
heap.push(getSol(u));
}
printf("%llu\n", sum);
return 0;
}
Loading

0 comments on commit 12da95d

Please sign in to comment.