@@ -6,18 +6,15 @@ function rectangleArea(rectangles: number[][]): number {
6
6
7
7
const total = { left, right, down, up } ;
8
8
const root = new SegmentNode ( total ) ;
9
- // console.log(root, total);
9
+
10
10
for ( const [ left , down , right , up ] of rectangles ) {
11
- change ( root , /* total, */ { left, right, down, up } , 1n ) ;
12
- // console.log(root, total);
11
+ change ( root , { left, right, down, up } , 1n ) ;
13
12
}
14
13
15
- // console.log(root)
16
14
return Number ( root . value % BigInt ( 10 ** 9 + 7 ) ) ;
17
15
}
18
16
function change (
19
17
node : SegmentNode ,
20
- // current: Interval,
21
18
target : Interval ,
22
19
value : bigint ,
23
20
) {
@@ -30,15 +27,13 @@ function change(
30
27
) {
31
28
return ;
32
29
}
33
- // console.log({ node, current, target, value });
34
30
35
31
if (
36
32
target . left <= current . left &&
37
33
target . down <= current . down &&
38
34
target . right >= current . right &&
39
35
target . up >= current . up
40
36
) {
41
- // console.log("找到了包含target的范围了");
42
37
if ( node . children . length === 0 ) {
43
38
node . value = value *
44
39
BigInt ( current . right - current . left ) *
@@ -54,7 +49,7 @@ function change(
54
49
current . down < a && current . up > a
55
50
) [ 0 ] ?? current . up ;
56
51
const subinterval = TwoDSplit ( current , midx , midy ) ;
57
- // console.log(current, subinterval);
52
+
58
53
if ( subinterval . length ) {
59
54
node . children = subinterval . map (
60
55
( c ) =>
@@ -66,18 +61,13 @@ function change(
66
61
) ,
67
62
) ;
68
63
}
69
- // console.log("创建子节点", node.value, node.children);
70
64
}
71
65
}
72
66
if ( node . children . length ) {
73
- // for (const [index, next] of subinterval.entries()) {
74
- // change(node.children[index], /* next, */ target, value);
75
- // }
76
-
77
67
for ( const child of node . children ) {
78
68
change ( child , target , value ) ;
79
69
}
80
- //可能没有子节点
70
+
81
71
node . value = node . children . length
82
72
? node . children . reduce ( ( a , n ) => a + n . value , 0n )
83
73
: node . value ;
0 commit comments