Skip to content

Commit

Permalink
4.30
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Apr 30, 2019
1 parent c3e166d commit 557cc19
Show file tree
Hide file tree
Showing 11 changed files with 774 additions and 103 deletions.
18 changes: 10 additions & 8 deletions Queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@
- [x] LOJ#2312. 「HAOI2017」八纵八横
- [x] LOJ#114. k 大异或和
- [ ] LOJ#6243. 关灯问题
- [ ] [WC2011]最大XOR和路径
- [x] bzoj4184
- [x] bzoj4269
# dp优化
Expand Down Expand Up @@ -203,7 +202,6 @@
- [x] [NOI2014]购票(可持久化单调队列)
- [ ] [NOI2016]国王饮水记
- [ ] BZOJ1096 [ZJOI2007]仓库建设
- [ ] [SDOI2016]征途
- [ ] HDU5956 The Elder
- [ ] P3994 Highway
- [x] bzoj3675
Expand Down Expand Up @@ -301,6 +299,9 @@
- [ ] LOJ6072
- [x] bzoj2111
- [ ] bzoj3501
- [ ] LOJ#6608. 无意识的石子堆
- [ ] LOJ#562. 「LibreOJ Round #9」Tangjz 的背包
- [ ] LOJ#6358. 前夕
# 扩展欧几里得
- [ ] LOJ#6440
- [ ] CF868G
Expand Down Expand Up @@ -345,6 +346,7 @@
- [ ] bzoj3532
- [ ] uoj77
- [x] Codeforces 786E ALT
- [ ] 【LOJ#3097】[SNOI2019]通信
# 分块及按大小分类
- [x] LOJ#6277-6285
- [x] bzoj2741
Expand Down Expand Up @@ -404,17 +406,16 @@
- [x] bzoj3589
# kdtree
- [x] LOJ#6016. 崂山白花蛇草水
- [ ] P4357 [CQOI2016]K远点对
- [x] P4357 [CQOI2016]K远点对
- [ ] bzoj2378
- [ ] bzoj2626
- [ ] bzoj2648
- [ ] bzoj2850
- [x] bzoj2626
- [x] bzoj2648
- [x] bzoj2850
- [ ] bzoj3616
- [ ] bzoj3815
- [ ] bzoj4066
# 计算几何
- [x] P4586
- [ ] bzoj2961
- [ ] bzoj2642
- [ ] LOJ#6504. 「雅礼集训 2018 Day5」Convex
- [x] LOJ#6360. 复燃「恋之埋火」
Expand All @@ -426,7 +427,7 @@
- [ ] P4383
# 左偏树
- [ ] P2483
- [ ] bzoj2809
- [x] bzoj2809
- [ ] bzoj2090
# 数论
- [x] PE484
Expand Down Expand Up @@ -469,6 +470,7 @@
- [ ] BZOJ4700: 适者
- [x] 「Heoi2013」Segment
- [x] bzoj3585
- [ ] bzoj3064 CPU监控
# 分治
- [x] UVA1608 Non-boring sequences
- [x] P4755 Beautiful Pair
Expand Down
2 changes: 2 additions & 0 deletions Review/Other/Owys.tex
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ \subsection{读入优化}
可以使用支持自定义buffer的std::strstream,不过要注意这个类在C++98中已被弃用。
也可以考虑使用sprintf。

{\bfseries 注意使用strtod/strtol时务必一次性读取完毕。}

Update:经过单步调试追踪到strtod在glibc中实现。其具体实现在
\_\_\_\_STRTOF\\\_INTERNAL(/stdlib/strtod\_l.c)中,其实现依赖GMP,性能。。。。
不过scanf的调用链为\_\_scanf(/stdio-common/scanf.c)$\rightarrow$
Expand Down
5 changes: 1 addition & 4 deletions Review/Polynomial/Advanced.tex
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,7 @@ \subsection{CZT}

该变形利用了$A_k$只在$[0,n-1]$处有贡献的性质。

如此便可以使用FFT计算循环卷积。

参考代码:
\lstinputlisting{Source/Templates/bzoj1919-CZT.cpp}
如此便可以使用FFT计算循环卷积,但卷积规模大了一倍。

事实上CZT是DFT的广义形式,注意到$\omega$的单位根性质并没有被用到,可以
使用其它数代替。
Expand Down
134 changes: 134 additions & 0 deletions Source/2-SAT/bzoj2649.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#include <algorithm>
#include <cstdio>
int read() {
int res = 0, c;
do
c = getchar();
while(c < '0' || c > '9');
while('0' <= c && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
return res;
}
void write(int x) {
if(x >= 10)
write(x / 10);
putchar('0' + x % 10);
}
const int size = 1000005, maxv = size * 4,
maxe = size * 2;
struct Edge {
int to, nxt;
} E[maxe];
int last[size * 2], cnt = 0;
void addEdgeImpl(int u, int v) {
++cnt;
E[cnt].to = v, E[cnt].nxt = last[u];
last[u] = cnt;
}
void addEdge(int u, int a, int v, int b) {
u = u << 1 | a, v = v << 1 | b;
addEdgeImpl(u, v);
addEdgeImpl(v ^ 1, u ^ 1);
}
int pre[size], nxt[size], n;
void genNxt(int u, int* ed, int& lcnt) {
int col = u & 1, id = u >> 1;
if(id <= n) {
if(col) {
if(pre[id])
ed[lcnt++] = (pre[id] + n) << 1;
ed[lcnt++] = (id + n) << 1 | 1;
}
} else {
int rid = id - n;
if(col) {
if(nxt[rid]) {
ed[lcnt++] = nxt[rid] << 1;
ed[lcnt++] = (nxt[rid] + n) << 1 | 1;
}
} else {
ed[lcnt++] = rid << 1;
if(pre[rid])
ed[lcnt++] = (pre[rid] + n) << 1;
}
}
}
int dfn[maxv], low[maxv], icnt = 0, st[maxv], top = 0,
col[maxv], ccnt = 0;
bool flag[maxv];
void DFS(int u);
void update(int u, int v) {
if(dfn[v]) {
if(flag[v])
low[u] = std::min(low[u], dfn[v]);
} else {
DFS(v);
low[u] = std::min(low[u], low[v]);
}
}
void DFS(int u) {
dfn[u] = low[u] = ++icnt;
flag[u] = true;
st[++top] = u;
if((u >> 1) <= n) {
for(int i = last[u]; i; i = E[i].nxt) {
int v = E[i].to;
update(u, v);
}
}
int ed[2], lcnt = 0;
genNxt(u, ed, lcnt);
for(int i = 0; i < lcnt; ++i)
update(u, ed[i]);
if(dfn[u] == low[u]) {
++ccnt;
int v;
do {
v = st[top--];
flag[v] = false;
col[v] = ccnt;
} while(v != u);
}
}
int gid[size], ans[size];
int main() {
n = read();
int m = read();
int k = read();
for(int i = 1; i <= m; ++i) {
int u = read();
int v = read();
addEdge(u, 0, v, 1);
}
for(int i = 1; i <= k; ++i) {
int w = read(), last = 0;
for(int j = 0; j < w; ++j) {
int u = read();
gid[u] = i;
ans[i] = u;
pre[u] = last;
nxt[last] = u;
last = u;
}
}
int end = n << 2 | 1;
for(int i = 2; i <= end; ++i) {
if(!dfn[i])
DFS(i);
if((i & 1) && col[i] == col[i ^ 1]) {
puts("NIE");
return 0;
}
}
puts("TAK");
for(int i = 1; i <= n; ++i)
if(col[i << 1 | 1] < col[i << 1])
ans[gid[i]] = i;
for(int i = 1; i <= k; ++i) {
write(ans[i]);
putchar(' ');
}
return 0;
}
14 changes: 7 additions & 7 deletions Source/2-SAT/bzoj3495.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ int main() {
int v = read();
addEdge(u, 0, v, 1);
}
int pcnt = n;
for(int t = 1; t <= k; ++t) {
int c = read();
int c = read(), last = 0;
for(int i = 0; i < c; ++i) {
int u = read(), id = ++pcnt;
addEdge(u, 1, id, 1);
int u = read();
addEdge(u, 1, u + n, 1);
if(i) {
addEdge(u, 1, id - 1, 0);
addEdge(id - 1, 1, id, 1);
addEdge(u, 1, last, 0);
addEdge(last, 1, u + n, 1);
}
last = u + n;
}
}
int end = pcnt * 2 + 1;
int end = n * 4 + 1;
for(int i = 2; i <= end; ++i) {
if(!dfn[i])
DFS(i);
Expand Down
133 changes: 133 additions & 0 deletions Source/K-d Tree/bzoj2626.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#include <algorithm>
#include <cstdio>
#include <set>
namespace IO {
char in[1 << 22];
void init() {
fread(in, 1, sizeof(in), stdin);
}
char getc() {
static char* S = in;
return *S++;
}
}
typedef long long Int64;
int read() {
int res = 0, c;
bool flag = false;
do {
c = IO::getc();
flag |= c == '-';
} while(c < '0' || c > '9');
while('0' <= c && c <= '9') {
res = res * 10 + c - '0';
c = IO::getc();
}
return flag ? -res : res;
}
const int size = 100005;
struct Pos {
int id, x, y;
} P[size];
Int64 dist(const Pos& a, const Pos& b) {
Int64 dx = a.x - b.x, dy = a.y - b.y;
return dx * dx + dy * dy;
}
bool cmpX(const Pos& a, const Pos& b) {
return a.x < b.x;
}
bool cmpY(const Pos& a, const Pos& b) {
return a.y < b.y;
}
struct Node {
int l, r, minx, maxx, miny, maxy;
void update(const Node& rhs) {
minx = std::min(minx, rhs.minx);
maxx = std::max(maxx, rhs.maxx);
miny = std::min(miny, rhs.miny);
maxy = std::max(maxy, rhs.maxy);
}
Int64 evalMax(const Pos& a) const {
Int64 dx1 = minx - a.x, dx2 = maxx - a.x;
Int64 dy1 = miny - a.y, dy2 = maxy - a.y;
return std::max(dx1 * dx1, dx2 * dx2) +
std::max(dy1 * dy1, dy2 * dy2);
}
} T[size];
#define ls T[u].l
#define rs T[u].r
int build(int l, int r, bool axis) {
if(l > r)
return 0;
int m = (l + r) >> 1;
std::nth_element(P + l, P + m, P + r + 1,
axis ? cmpX : cmpY);
T[m].minx = T[m].maxx = P[m].x;
T[m].miny = T[m].maxy = P[m].y;
axis ^= 1;
T[m].l = build(l, m - 1, axis);
T[m].r = build(m + 1, r, axis);
if(T[m].l)
T[m].update(T[T[m].l]);
if(T[m].r)
T[m].update(T[T[m].r]);
return m;
}
struct Info {
Int64 d;
int u;
Info(Int64 d, int u) : d(d), u(u) {}
bool operator<(const Info& rhs) const {
if(d != rhs.d)
return d < rhs.d;
return u > rhs.u;
}
};
typedef std::set<Info> Heap;
Heap cur;
void query(const Pos& p, int u) {
if(u == 0)
return;
{
Info md(dist(p, P[u]), P[u].id);
if(*cur.begin() < md) {
cur.erase(cur.begin());
cur.insert(md);
}
}
Int64 lv = T[ls].evalMax(p), rv = T[rs].evalMax(p);
if(lv > rv) {
if(lv >= cur.begin()->d)
query(p, ls);
if(rv >= cur.begin()->d)
query(p, rs);
} else {
if(rv >= cur.begin()->d)
query(p, rs);
if(lv >= cur.begin()->d)
query(p, ls);
}
}
int main() {
IO::init();
int n = read();
for(int i = 1; i <= n; ++i) {
P[i].id = i;
P[i].x = read();
P[i].y = read();
}
int rt = build(1, n, false);
int m = read();
for(int i = 0; i < m; ++i) {
Pos p;
p.x = read();
p.y = read();
int k = read();
cur.clear();
for(int j = 0; j < k; ++j)
cur.insert(Info(-1, -j));
query(p, rt);
printf("%d\n", cur.begin()->u);
}
return 0;
}
Loading

0 comments on commit 557cc19

Please sign in to comment.