Skip to content

Commit

Permalink
first obsidian article
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzqm committed Dec 3, 2024
1 parent 8928236 commit 73d7d50
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/content/.obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@
},
"active": "acab4254ffc5cac4",
"lastOpenFiles": [
"attachments/Pasted image 20241202190606.png",
"attachments/row_echelon.excalidraw.md",
"attachments/Pasted Image 20241202190055_929.png",
"attachments/Pasted Image 20241202190043_594.png",
"attachments/lucky-number 2024-12-02 18.59.24.excalidraw.md",
"blog/Untitled.md",
"blog/lucky-number.md",
"blog/test.md",
"attachments/Pasted image 20241202122801.png",
"blog/attachments/Pasted image 20241202122406.png",
"blog/attachments",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions src/content/attachments/row_echelon.excalidraw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---

excalidraw-plugin: parsed
tags: [excalidraw]

---
==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠== You can decompress Drawing data with the command palette: 'Decompress current Excalidraw file'. For more info check in plugin settings under 'Saving'


# Excalidraw Data
## Text Elements
## Embedded Files
a5599902881b860e36684662e3b3984dcc5d9adb: [[Pasted Image 20241202190043_594.png]]

96009f909898850f128bef2e80a386a783d290e3: [[Pasted Image 20241202190055_929.png]]

%%
## Drawing
```compressed-json
N4KAkARALgngDgUwgLgAQQQDwMYEMA2AlgCYBOuA7hADTgQBuCpAzoQPYB2KqATLZMzYBXUtiRoIACyhQ4zZAHoFAc0JRJQgEYA6bGwC2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omSBjoDrWlgMdOBZ1EGXV9Gg02mjMbYKjKsfBX1CHgpTP/KhyMHm5kbHAoscNuCrB
YfDNhubV6cPouXDsAiEBCNQOiIQojCafVJpsn6yaRa/jkQDSWYFS2gVUbBZFlVkI6P7Hox0vZMCz3QLGSgdlmUVBIpwKAIpCBGEfEFX0C6aW3SFDFNVkxmUwqIMoUs6BggtBZZVIsUBzAEAPVCY90BLQyj0NkXA4YmCRoSaUAkUJwwEBneOud8IhBQDYJ0cIy7Hw1rrfLN9AAJaepV+6JXaOpcAV0qpwHJdhR8WloAQkyBUQ9MJFgMEIAgCgJljU
9XvhIY+LR6MMapBAbAIh2oNF7PoMUs0aMnwvoakjLGC68nYxkSjN9qM6vNUNZ+AnWPCY4zS0aQCPUbUKMxuTOSONcadQtF1pRBNsa0/vTU7rdSetk0JzTGROhbXAYmvakADPyYyK5Q6gbYEWcMxkGlG6t34B3Z55z+gfPZCXSuoEtV1OWa2Rx/9sLD33tPeexzGmYsZDFNCtFCKQgYJbVFrz+gxzMiyxQDFUZ4XYrU05qz+gSt2UZegHqTGJIYmF
MeBs9tkg8VBvFP2G8SMtbxPgAAmrml4TxXigwzQcdpcsIBGDYAYNZF6CC1t2kS/TqWRP6Bs8TCBEgmskYZCQMLq7IvHeIGKBAfTUBqvgSQEYL0iu4E0MEXRGFoP3dNf1VAJKTJ4hpqQZQNIAAUbTmG8HuNQSHEP57tAAJQyjA8oEM5IKhA9B+ylEvBQbQ6x9DuHiONspei9prErkr2cGbY9UoN1MhgYjKQdJRCUUcBe297gUHFJEBu1zx0bOCNoD
5/tYDMFIOkFrcTiAdgDz7hyCKNncBHsIGe69glI71XYCvYwOyi38DLa5tMSU6QteMMUrhED+h6tG6TTT+W2j1cfaQqEmFpudd67mSUQWFCBTGw9MAD8b4gA=
```
%%
34 changes: 34 additions & 0 deletions src/content/blog/lucky-number.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
date: 2024-12-02
title: "OI #2: Lucky Number"
image: https://art.npanuhin.me/SVG/Codeforces/Codeforces.colored.svg
---
Here's the [problem statement](https://loj.ac/p/2013); it's again written in Chinese so here's the English summary. You're given a tree with $N \leq 20000$ nodes which each have a value written on them. You must answer $Q \leq 200000$ queries which each ask, for a given simple path between two nodes $u$ and $v$, what is the maximum value that can be formed by XOR-ing values of nodes along that path (including $u$ and $v$)?

## XOR Basis

The core of this problem is the following: given a set of $n$ numbers, how can I find the maximum XOR of any subset of these numbers? Here's a great [Stack Exchange article](https://math.stackexchange.com/questions/48682/maximization-with-xor-operator) about this problem, but I urge you to read through this article first and consult the Stack Exchange article only if you get stuck.

To start, let's consider a reduced subproblem. Define the *dimension* of a number $x$ to be the position of its highest bit. How can we solve this problem if our set contains at most one number in each dimension? (Again, the answer is in the Stack Exchange article, but I urge you to think it through yourself first.)

Once we've figured that out, we just need a way to somehow reduce our set to a set which satisfies this condition. More formally, define the *span* of our set $S$ to be the set of all possible XORs of its subsets: we wish to find a set $T$ with the same span, but which contains at most one number in each dimension.

The linear algebra terminology is deliberate, as this idea of "eliminating" dimensional redundancy is at the core of **Gaussian elimination.** Although its most well-known application is to solve systems of linear equations, what we care about here is its ability to convert a matrix (i.e. a set of vectors) into *row-echelon form*, which is exactly what our condition is describing: a set of vectors, with at most one vector in each dimension.

![](../attachments/Pasted%20image%2020241202190606.png)

*A matrix and its row-echelon form. Verify that the row space (span of the row vectors) of both matrices are the same, and that the row-echelon matrix has only one vector in each dimension.*

To make this concrete, let's step away from XOR for a second and think about how this process works in linear space. Say we have the 3 vectors $\langle 1, 1, 1\rangle, \langle2, 2, 3\rangle, \langle1, 2, 3\rangle$. We can "reduce" this set by picking one 3D vector—say, $\langle 1, 1, 1\rangle$—and "eliminating" the others with it. For instance, consider the span of $\langle 1, 1, 1\rangle$ and $\langle 2, 2, 3\rangle$, which consists vectors of the form $a\langle 1, 1, 1\rangle + b\langle 2, 2, 3\rangle$, where $a$ and $b$ are arbitrary scalars. However, we can rewrite this as
$$
a\langle 1, 1, 1\rangle + b(2\langle 1, 1, 1\rangle + \langle 0, 0, 1\rangle)
= (a + 2b)\langle 1, 1, 1\rangle + b\langle 0, 0, 1\rangle
$$
Which is just the span of $\langle 1, 1, 1\rangle$ and $\langle 0, 0, 1\rangle$. Therefore, we can "reduce" $\langle 2, 2, 3\rangle$ to $\langle 0, 0, 1\rangle$: **this**, not solving systems of equations, is the core idea of Gaussian elimination. Now, see if you can apply this method to reducing bit-vectors under XOR!

## Closing Thoughts

The rest of the problem is pretty fun and simple, so I'll leave it to you as an exercise. This problem is the first time I've encountered the idea of XOR basis, so I thought it would be nice to write this little blog about it!

That's it for this problem; As always, [here's my submission](https://loj.ac/s/2212034) in case you get stuck.

0 comments on commit 73d7d50

Please sign in to comment.