Skip to content

Commit

Permalink
5.22d
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed May 22, 2019
1 parent e979664 commit 82eff73
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions Queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@
- [ ] bzoj3984
- [x] bzoj4311
- [ ] bzoj4456
- [x] LOJ534
# BM 算法
- [ ] LOJ#2981. 「THUSCH 2017」如果奇迹有颜色
# 概率期望
Expand Down
4 changes: 4 additions & 0 deletions Review/DataStructure/SegTree.tex
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ \subsubsection{例题 [FJOI2015]火星商店问题}

参考代码:
\lstinputlisting{Source/Source/SegmentTree/P4585.cpp}

Update:即使像LOJ\#534. 「LibreOJ Round \#6」花团这种强制在线的题目,也可以分治+
线段树分治解决。

\subsection{线段树优化建图}
对于一个点到一个或多个连续区间内的点有连边且区间内的边权相等,考虑使用线段树优化建图。
即使用线段树的上层节点代表管辖区间内的所有节点,建树时上层节点向左右儿子连权值为0的边
Expand Down
70 changes: 70 additions & 0 deletions Source/Partition/LOJ534.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
const int size = 15005;
int n, maxv, t, d, dp[20][size];
typedef std::pair<int, int> Item;
std::vector<Item> item[size << 2];
#define ls l, m, id << 1
#define rs m + 1, r, id << 1 | 1
void insert(int l, int r, int id, int nl, int nr,
const Item& it) {
if(nl <= l && r <= nr)
item[id].push_back(it);
else {
int m = (l + r) >> 1;
if(nl <= m)
insert(ls, nl, nr, it);
if(m < nr)
insert(rs, nl, nr, it);
}
}
void solve(int l, int r, int id, int dep) {
if(item[id].size()) {
++dep;
memcpy(dp[dep], dp[dep - 1],
sizeof(int) * maxv);
int* cdp = dp[dep];
for(Item it : item[id]) {
int v = it.first, w = it.second;
for(int i = maxv; i >= v; --i)
cdp[i] =
std::max(cdp[i], cdp[i - v] + w);
}
}
if(l == r) {
int op;
scanf("%d", &op);
if(op == 1) {
int v, w, e;
scanf("%d%d%d", &v, &w, &e);
v -= d, w -= d, e -= d;
if(l < e)
insert(1, n, 1, l + 1, e, Item(v, w));
} else {
int v;
scanf("%d", &v);
v -= d;
int res = dp[dep][v];
if(res >= 0) {
printf("1 %d\n", res);
if(t)
d = res ^ 1;
} else
puts("0 0"), d = 0;
}
} else {
int m = (l + r) >> 1;
solve(ls, dep);
solve(rs, dep);
}
}
int main() {
scanf("%d%d%d", &n, &maxv, &t);
++maxv;
memset(dp, 0xc0, sizeof(dp));
dp[0][0] = 0;
solve(1, n, 1, 0);
return 0;
}

0 comments on commit 82eff73

Please sign in to comment.