Skip to content

Commit 69c561c

Browse files
authored
Merge branch 'main' into compress_tree
2 parents 3f89810 + 0f8e5bd commit 69c561c

25 files changed

+417
-83
lines changed

Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,15 @@ path = "examples/monotonic/count_rects.rs"
219219
[[example]]
220220
name = "cartesian_tree"
221221
path = "examples/monotonic/cartesian_tree.rs"
222+
223+
[[example]]
224+
name = "fenwick_kth"
225+
path = "examples/data_structures/fenwick_kth.rs"
226+
227+
[[example]]
228+
name = "disjoint_rmq_non_commutative"
229+
path = "examples/data_structures/disjoint_rmq_non_commutative.rs"
230+
231+
[[example]]
232+
name = "lca_rmq_next_on_path"
233+
path = "examples/graphs/lca_rmq_next_on_path.rs"

examples/data_structures/binary_trie.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
for _ in 0..q {
1313
input! {
1414
t: u8,
15-
x: usize,
15+
x: u32,
1616
}
1717

1818
match t {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// verification-helper: PROBLEM https://judge.yosupo.jp/problem/queue_operate_all_composite
2+
3+
use proconio::input;
4+
use programming_team_code_rust::data_structures::disjoint_rmq::DisjointRMQ;
5+
6+
const MOD: u64 = 998_244_353;
7+
8+
fn main() {
9+
input! {
10+
q: usize,
11+
}
12+
13+
let mut que = Vec::new();
14+
let mut front = 0;
15+
let mut queries = Vec::new();
16+
17+
for _ in 0..q {
18+
input! {
19+
t: u8,
20+
}
21+
match t {
22+
0 => {
23+
input! {
24+
a: u64,
25+
b: u64,
26+
}
27+
que.push((a, b));
28+
}
29+
1 => {
30+
front += 1;
31+
}
32+
_ => {
33+
input! {
34+
x: u64,
35+
}
36+
queries.push((front..que.len(), x));
37+
}
38+
}
39+
}
40+
41+
let d_rmq = DisjointRMQ::new(&que, |&a, &b| (a.0 * b.0 % MOD, (b.0 * a.1 + b.1) % MOD));
42+
43+
for (range, x) in queries {
44+
if range.is_empty() {
45+
println!("{}", x);
46+
} else {
47+
let (slope, y_int) = d_rmq.query(range);
48+
println!("{}", (slope * x + y_int) % MOD);
49+
}
50+
}
51+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// verification-helper: PROBLEM https://judge.yosupo.jp/problem/predecessor_problem
2+
3+
use proconio::input;
4+
use programming_team_code_rust::data_structures::fenwick::Fenwick;
5+
6+
fn main() {
7+
input! {
8+
n: usize,
9+
q: usize,
10+
s: String,
11+
}
12+
13+
let mut fenwick =
14+
Fenwick::<i32>::build_on_array(&s.chars().map(|c| (c == '1') as i32).collect::<Vec<_>>());
15+
16+
for _ in 0..q {
17+
input! {
18+
t: u8,
19+
k: usize,
20+
}
21+
match t {
22+
0 => {
23+
if fenwick.sum(k..k + 1) == 0 {
24+
fenwick.add(k, 1);
25+
}
26+
}
27+
1 => {
28+
if fenwick.sum(k..k + 1) == 1 {
29+
fenwick.add(k, -1);
30+
}
31+
}
32+
2 => {
33+
println!("{}", fenwick.sum(k..k + 1));
34+
}
35+
3 => {
36+
let cnt = fenwick.sum(0..k);
37+
let res = fenwick.kth(cnt + 1);
38+
if res == n {
39+
println!("-1");
40+
} else {
41+
println!("{}", res);
42+
}
43+
}
44+
_ => {
45+
let cnt_le = fenwick.sum(0..k + 1);
46+
if cnt_le == 0 {
47+
println!("-1");
48+
} else {
49+
println!("{}", fenwick.kth(cnt_le));
50+
}
51+
}
52+
}
53+
}
54+
}

examples/data_structures/rmq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
a: [usize; n],
1111
}
1212

13-
let rmq = RMQ::new(&a, std::cmp::min);
13+
let rmq = RMQ::new(&a, |&x, &y| std::cmp::min(x, y));
1414
for _ in 0..q {
1515
input! {
1616
le: usize,

examples/data_structures/seg_tree_aizu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() {
88
n: usize,
99
q: usize,
1010
}
11-
let mut st = SegTree::<usize>::new(n, |x, y| x + y, 0);
11+
let mut st = SegTree::new(n, |x, y| x + y, 0);
1212
for _ in 0..q {
1313
input! {
1414
t: u8,

examples/data_structures/seg_tree_yosupo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() {
2121
})
2222
.collect::<Vec<(u64, u64)>>();
2323

24-
let mut seg_tree = SegTree::<(u64, u64)>::build_on_array(
24+
let mut seg_tree = SegTree::build_on_array(
2525
&a,
2626
|x, y| (x.0 * y.0 % MOD, (y.0 * x.1 + y.1) % MOD),
2727
(1, 0),

examples/graphs/hld_path_composite_yosupo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ fn main() {
3939
input_a[hld.tin[i]] = elem;
4040
}
4141

42-
let mut st_forwards = SegTree::<(u64, u64)>::build_on_array(
42+
let mut st_forwards = SegTree::build_on_array(
4343
&input_a,
4444
|x, y| (x.0 * y.0 % MOD, (y.0 * x.1 + y.1) % MOD),
4545
(1, 0),
4646
);
47-
let mut st_backwards = SegTree::<(u64, u64)>::build_on_array(
47+
let mut st_backwards = SegTree::build_on_array(
4848
&input_a,
4949
|x, y| (x.0 * y.0 % MOD, (x.0 * y.1 + x.1) % MOD),
5050
(1, 0),
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// verification-helper: PROBLEM https://judge.yosupo.jp/problem/tree_diameter
2+
3+
use proconio::input;
4+
use programming_team_code_rust::graphs::lca::LCA;
5+
6+
fn main() {
7+
input! {
8+
n: usize,
9+
}
10+
11+
let mut adj = vec![vec![]; n];
12+
let mut adj_w = vec![vec![]; n];
13+
for _ in 1..n {
14+
input! {
15+
u: usize,
16+
v: usize,
17+
w: i64,
18+
}
19+
adj[u].push(v);
20+
adj[v].push(u);
21+
adj_w[u].push((v, w));
22+
adj_w[v].push((u, w));
23+
}
24+
25+
let lca = LCA::new(&adj);
26+
27+
let mut dist_root = vec![0; n];
28+
fn dfs(u: usize, p: Option<usize>, adj_w: &[Vec<(usize, i64)>], dist_root: &mut Vec<i64>) {
29+
for &(v, w) in &adj_w[u] {
30+
if Some(v) == p {
31+
continue;
32+
}
33+
dist_root[v] = w + dist_root[u];
34+
dfs(v, Some(u), adj_w, dist_root);
35+
}
36+
}
37+
38+
dfs(0, None, &adj_w, &mut dist_root);
39+
40+
let dist_path =
41+
|u: usize, v: usize| -> i64 { dist_root[u] + dist_root[v] - 2 * dist_root[lca.lca(u, v)] };
42+
43+
let mut u = 0;
44+
for i in 1..n {
45+
if dist_path(0, u) < dist_path(0, i) {
46+
u = i;
47+
}
48+
}
49+
50+
let mut v = 0;
51+
for i in 1..n {
52+
if dist_path(u, v) < dist_path(u, i) {
53+
v = i;
54+
}
55+
}
56+
57+
println!("{} {}", dist_path(u, v), lca.dist(u, v) + 1);
58+
59+
print!("{} ", u);
60+
while u != v {
61+
u = lca.next_on_path(u, v);
62+
print!(" {}", u);
63+
}
64+
println!();
65+
}

examples/helpers/lis_aizu.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@ fn main() {
1111

1212
let mut lis = Lis::default();
1313

14-
for elem in a {
14+
assert_eq!(lis.get_lis(), vec![]);
15+
16+
for &elem in &a {
1517
lis.push(elem);
1618
}
1719

18-
println!("{}", lis.dp.len());
20+
let idxs = lis.get_lis();
21+
for i in 1..idxs.len() {
22+
assert!(a[idxs[i - 1]] < a[idxs[i]]);
23+
}
24+
25+
println!("{}", idxs.len());
1926
}

0 commit comments

Comments
 (0)