AACPOJ Note Writing Guide
Quick Index
If you want to look up syntax, start with "Markdown Basic Syntax Quick Reference" or jump directly to "LaTeX Math Quick Reference". If you are joining the C++ syntax camp for the first time, start with the shorter beginner guide: C++ Syntax Camp Note Guide (Traditional Chinese).
- Why Write Problem Notes?
- How to Use AACPOJ Notes
- What Should a Note Record?
- Markdown Basic Syntax Quick Reference
- LaTeX Math Quick Reference
- Sharing, Layout, and Preview
- Example of a Good Note
- Summary
Why Write Problem Notes?
The main purpose of competitive programming notes is to help your future self rebuild the solution idea quickly. If a note only says "DP" or "use a segment tree", it will not help much months later. A useful note records the reasoning chain, key observations, and mistakes you already made.
A good note is more than a copied solution. It is a record of how you learned the problem: where you got stuck, what changed your approach, why the first idea failed, and what pattern you can reuse next time.
How to Use AACPOJ Notes
AACPOJ notes support Markdown + LaTeX math. These are the basic rules to use when writing a new note:
- Inline math uses
$...$; display math uses$$...$$. ~~...~~is strikethrough. Use it only when you want crossed-out text.- Checklists support
- [ ]and- [x]. - Prefer normal Markdown. Raw HTML may be filtered for security.
- Note visibility can be private, class-only, or public. A good workflow is to start private, then share after cleanup.
- Notes have layout styles: plain, paper, and Kindle. The plain style is best for announcements, guides, and short references.
What Should a Note Record?
You do not need every item for every problem. Pick the parts that will help your future self the most.
Problem Summary (Abstract)
Use one or two sentences to describe the mathematical core of the problem. Remove the story.
- Less useful: "Someone wants to send gifts to friends..."
- Better: "Given an array \(a\), find the minimum \(k\) such that \(\sum a_i \le k\)."
This makes the note easy to scan later.
Key Observations / Properties
This is usually the most valuable part of the note. Write down the property that made the problem solvable:
- The answer is monotonic, so binary search applies.
- After \(k\) operations, only the first \(\log n\) positions can change.
- The problem can be modeled as a graph: vertices are states, edges are transitions.
- For a fixed right endpoint \(r\), the best left endpoint \(l\) can be maintained with two pointers.
Thought Process
The path from a simple idea to the accepted solution is often more useful than the final answer alone.
- First idea: \(O(n^2)\) brute force, enumerate all previous positions.
- Improvement 1: Notice repeated computation and use prefix sums, reducing it to \(O(n)\).
- Improvement 2: Notice monotonicity and use a monotonic queue for a cleaner implementation.
Mistakes / Common Pitfalls
Write down the bugs you actually hit:
- Forgot to use
long long. - Binary search condition was reversed.
- Used 0-indexing and 1-indexing in the same formula.
- Forgot to clear arrays between test cases.
- DP initialization missed impossible states.
These records are especially useful because they are your own weak spots.
Similar Problems / Extensions
If the problem reminds you of another problem, record the link or problem code. After solving several related problems, you will start seeing patterns.
Complexity and Tags
Write time and memory complexity, plus a few tags:
Time: $O(n \log n)$
Memory: $O(n)$
Tags: `#binary-search` `#greedy` `#prefix-sum`
Markdown Basic Syntax Quick Reference
Heading Levels
Use #, ##, and ### to create sections. In most notes, ## and ### are enough.
## Idea
### Key Observation
### Implementation Details
Do not use headings just to make text larger. Headings should describe structure.
Bold, Italic, Strikethrough
**important**
*emphasis*
~~wrong idea~~
Rendered:
important
emphasis
wrong idea
Lists
- Step 1: read input
- Step 2: sort
- Step 3: sweep once
1. Brute force
2. Optimize
3. Prove correctness
Use unordered lists for reminders and ordered lists for sequences.
Checklist
- [x] Use `long long`
- [x] Check boundary cases
- [ ] Rewrite proof
A checklist is good for bugs, TODOs, and things to verify before submitting.
Code
Inline code uses backticks:
Use `vector<int>` to store the array.
Code blocks use triple backticks. Add the language name for highlighting:
```cpp
long long ans = 0;
for (int i = 0; i < n; i++) {
ans += a[i];
}
```
Rendered:
long long ans = 0;
for (int i = 0; i < n; i++) {
ans += a[i];
}
Quote Blocks
> Key observation: when $n$ is even, a solution must exist.
Rendered:
Key observation: when \(n\) is even, a solution must exist.
Tables
Tables are useful for comparing approaches, listing complexities, or matching constraints with methods:
| Method | Time | Memory | Note |
|---|---|---|---|
| Brute force | $O(n^2)$ | $O(n)$ | Works for $n \le 5000$ |
| Segment tree | $O(n \log n)$ | $O(n)$ | Accepted solution |
AACPOJ also supports column alignment:
| Default | Left | Center | Right |
|---|:---|:---:|---:|
| normal | left | center | right |
| $O(n)$ | $a_i$ | $x \in S$ | $10^9+7$ |
Rendered:
| Default | Left | Center | Right |
|---|---|---|---|
| normal | left | center | right |
| \(O(n)\) | \(a_i\) | \(x \in S\) | \(10^9+7\) |
The rule is simple: :--- means left-aligned, :---: means centered, and ---: means right-aligned. If a table becomes too wide or dense, use headings or lists instead.
Links
[Problem link](https://example.com)
[Jump to LaTeX section](#latex-math-quick-reference)
Use descriptive link text. Avoid writing only "click here".
Horizontal Rules
---
Use horizontal rules to separate large sections. Do not add one after every small paragraph.
LaTeX Math Quick Reference
This is the main lookup section. To find a symbol, start with "LaTeX Symbol Table". For multi-line formulas, see the DP, cases, and aligned derivation examples later.
Inline Math and Display Math
Inline math goes inside a sentence with $...$:
When $n \le 10^5$, an $O(n \log n)$ solution can pass.
Rendered:
When \(n \le 10^5\), an \(O(n \log n)\) solution can pass.
Display math uses $$...$$ as its own block. Leave a blank line before and after it:
For every $i$,
$$
\sum_{j=1}^{i} a_j \ge \lfloor \log_2 i \rfloor
$$
this inequality always holds.
Rendered:
For every \(i\),
\[\sum_{j=1}^{i} a_j \ge \lfloor \log_2 i \rfloor\]this inequality always holds.
If you only want to show the raw LaTeX source in a guide, put it in a code block or backticks, for example `$O(n \log n)$`.
LaTeX Symbol Table
Common competitive programming symbols are grouped here. Copy from the source column and check the rendered result on the right.
Category shortcuts: Variables / Brackets, Comparison / Logic / Quantifiers, Operations / Rounding / Complexity, Sums / Ranges, Graph / Sets / Combinatorics, Greek Letters.
Variables / Brackets
| Meaning | Source | Result |
|---|---|---|
| Subscript | $a_i$ |
\(a_i\) |
| Multi-character subscript | $a_{i,j}$ |
\(a_{i,j}\) |
| Superscript | $a^2$ |
\(a^2\) |
| Multi-character superscript | $a^{n+1}$ |
\(a^{n+1}\) |
| DP state | $dp_i$, $dp_{i,j}$ |
\(dp_i\), \(dp_{i,j}\) |
| Auto-sized parentheses | $\left(\frac{a}{b}\right)$ |
\(\left(\frac{a}{b}\right)\) |
| Set braces | $\{a,b,c\}$ |
\(\{a,b,c\}\) |
| Absolute value | $\lvert x \rvert$ |
\(\lvert x \rvert\) |
Comparison / Logic / Quantifiers
| Meaning | Source | Result |
|---|---|---|
| Less/greater than or equal | $\le$, $\ge$ |
\(\le\), \(\ge\) |
| Not equal | $\neq$ |
\(\neq\) |
| Approximately equal | $\approx$ |
\(\approx\) |
| Implies | $\Rightarrow$ |
\(\Rightarrow\) |
| If and only if | $\Longleftrightarrow$ |
\(\Longleftrightarrow\) |
| And / or / not | $\land$, $\lor$, $\neg$ |
\(\land\), \(\lor\), \(\neg\) |
| For all | $\forall i$ |
\(\forall i\) |
| Exists | $\exists x$ |
\(\exists x\) |
| In / not in | $x \in S$, $x \notin S$ |
\(x \in S\), \(x \notin S\) |
Operations / Rounding / Complexity
| Meaning | Source | Result |
|---|---|---|
| Multiplication dot | $a \cdot b$ |
\(a \cdot b\) |
| Multiplication sign | $a \times b$ |
\(a \times b\) |
| Modulo | $a \bmod m$ |
\(a \bmod m\) |
| Minimum / maximum | $\min(a,b)$, $\max(a,b)$ |
\(\min(a,b)\), \(\max(a,b)\) |
| Fraction | $\frac{a}{b}$ |
\(\frac{a}{b}\) |
| Square root | $\sqrt{n}$ |
\(\sqrt{n}\) |
| Logarithm | $\log n$, $\log_2 n$ |
\(\log n\), \(\log_2 n\) |
| Floor | $\lfloor x \rfloor$ |
\(\lfloor x \rfloor\) |
| Ceiling | $\lceil x \rceil$ |
\(\lceil x \rceil\) |
| Complexity | $O(n \log n)$ |
\(O(n \log n)\) |
| Ten to the fifth | $10^5$ |
\(10^5\) |
| Two times ten to the fifth | $2 \times 10^5$ |
\(2 \times 10^5\) |
| Common moduli | $10^9+7$, $998244353$ |
\(10^9+7\), \(998244353\) |
Sums / Ranges
| Meaning | Source | Result |
|---|---|---|
| Sum | $\sum_{i=1}^{n} a_i$ |
\(\sum_{i=1}^{n} a_i\) |
| Product | $\prod_{i=1}^{n} a_i$ |
\(\prod_{i=1}^{n} a_i\) |
| Closed interval | $[1,n]$ |
\([1,n]\) |
| Half-open interval | $(l,r]$ |
\((l,r]\) |
| Integer range | $1 \le n \le 2 \times 10^5$ |
\(1 \le n \le 2 \times 10^5\) |
| Array value range | $0 \le a_i < 10^9+7$ |
\(0 \le a_i < 10^9+7\) |
Graph / Sets / Combinatorics
| Meaning | Source | Result |
|---|---|---|
| Graph | $G=(V,E)$ |
\(G=(V,E)\) |
| Edge in graph | $(u,v) \in E$ |
\((u,v) \in E\) |
| Distance array | $dist_s[v]$ |
\(dist_s[v]\) |
| Degree | $\deg(v)$ |
\(\deg(v)\) |
| Shortest-path relaxation | $dist[v] > dist[u] + w$ |
\(dist[v] > dist[u] + w\) |
| Subset | $A \subseteq B$ |
\(A \subseteq B\) |
| Proper subset | $A \subset B$ |
\(A \subset B\) |
| Union / intersection | $A \cup B$, $A \cap B$ |
\(A \cup B\), \(A \cap B\) |
| Empty set | $\emptyset$ |
\(\emptyset\) |
| Combination | $\binom{n}{k}$ |
\(\binom{n}{k}\) |
Greek Letters
| Meaning | Source | Result |
|---|---|---|
| alpha / beta | $\alpha$, $\beta$ |
\(\alpha\), \(\beta\) |
| gamma / delta | $\gamma$, $\delta$ |
\(\gamma\), \(\delta\) |
| epsilon | $\epsilon$, $\varepsilon$ |
\(\epsilon\), \(\varepsilon\) |
| theta | $\theta$, $\Theta$ |
\(\theta\), \(\Theta\) |
DP / Recurrences / Cases
DP transitions are easier to read as display math:
$$
dp_i = \min_{0 \le j < i} (dp_j + cost(j+1, i))
$$
Rendered:
\[dp_i = \min_{0 \le j < i} (dp_j + cost(j+1, i))\]Use cases for piecewise definitions:
$$
dp_i =
\begin{cases}
0, & i = 0 \\
dp_{i-1} + a_i, & i > 0
\end{cases}
$$
Rendered:
\[dp_i = \begin{cases} 0, & i = 0 \\ dp_{i-1} + a_i, & i > 0 \end{cases}\]Aligned Derivations
Use aligned for multi-line derivations:
$$
\begin{aligned}
\sum_{i=1}^{n} i
&= 1 + 2 + \cdots + n \\
&= \frac{n(n+1)}{2}
\end{aligned}
$$
Rendered:
\[\begin{aligned} \sum_{i=1}^{n} i &= 1 + 2 + \cdots + n \\ &= \frac{n(n+1)}{2} \end{aligned}\]& marks the alignment point, usually before the equals sign. Use \\ for a line break.
Common LaTeX Mistakes
- Missing the closing
$:$O(n log n)may turn the following text into math. - Writing
_outside math: use$a_i$, not plaina_i. - Writing Chinese or long English sentences inside math: keep text outside and put only variables/symbols in math.
- Visible braces need escaping: write
$\{1,2,3\}$, not${1,2,3}$. - Prefer
$\lvert x \rvert$for absolute value; it is less confusing around tables than$|x|$. - Display math should have blank lines before and after it.
- If a formula is too long, use
$$...$$instead of squeezing it inline. - If you only want to show source code, put it in a code block.
Sharing, Layout, and Preview
Visibility
AACPOJ notes can be private, class-only, or public:
- Private: best for drafts and personal review.
- Class-only: useful for discussion with classmates or teachers.
- Public: use this after the note is cleaned up and useful to others.
Layout Style
For most problem notes, use the plain style. It is clean and good for reading code, formulas, and tables. Paper and Kindle styles only change the reading experience; they do not change the Markdown source.
Preview
The editor has edit, split, and preview modes. Before saving, check the preview at least once:
- TOC links jump to the correct section.
- Math formulas render correctly.
- Code blocks have the right language and highlighting.
- Tables align correctly.
- Checklists become checkboxes.
- Heading levels are not confusing.
- Links open correctly.
Example of a Good Note
This is a useful skeleton. Start with it, then remove sections that do not matter for the problem.
## Problem Summary
Given an array of length $n$, minimize ...
## Constraints
- $1 \le n \le 2 \times 10^5$
- $1 \le a_i \le 10^9$
## Key Observations
1. The answer is monotonic in $k$, so binary search applies.
2. For a fixed $k$, feasibility can be checked in one linear scan.
## Thought Process
- **Brute force**: enumerate every $k$, $O(n^2)$, TLE.
- **Optimization**: binary search + linear check, becoming $O(n \log n)$.
## Implementation Details
- Binary search range: `[1, max(a)]`
- `valid(k)` function: ...
## Mistakes
- [x] Used `l = mid` in binary search and caused TLE.
- [x] Forgot `long long`, causing overflow while summing.
- [ ] Before rewriting, check the monotonic direction of `valid(k)`.
## Complexity
- Time: $O(n \log V)$
- Memory: $O(n)$
## Core Code
```cpp
bool valid(long long k) {
// ...
}
int main() {
long long lo = 1, hi = 1000000000LL;
while (lo < hi) {
long long mid = (lo + hi) / 2;
if (valid(mid)) hi = mid;
else lo = mid + 1;
}
cout << lo << '\n';
}
```
## Similar Problems
- CF 1234A (same binary-search pattern)
- ABC 321D (extension: add DP)
Tags: `#binary-search` `#greedy`
Summary
The first rule of note writing is: write for your future self.
Recording key observations, thought process, and mistakes is more valuable than copying a finished solution. With Markdown headings, lists, checklists, code blocks, tables, and LaTeX formulas, you can build notes that still help you understand the problem when you come back later.
快速目錄
想查語法時,可以先看「Markdown 基本語法速查」或直接跳到「LaTeX 數學式速查」。如果你是第一次參加 C++ 語法營,建議先看比較短的 C++ 語法營上課筆記入門。
為什麼要寫題目筆記?
寫競程題目筆記最主要的目的,是未來回來複習時,能讓當時的你用最少的時間回想起整題的思路。如果只寫「這題是 DP」、「用線段樹」,幾個月後再看基本沒用;但如果筆記裡有思路鏈、關鍵觀察、陷阱紀錄,就能在幾分鐘內把整題重新建立起來。
一個好的筆記不只是解法紀錄,更是你自己的學習軌跡:哪裡卡住、怎麼突破、為什麼一開始想錯、下次遇到類似題可以套什麼模式。久了累積下來,就是你自己的「知識庫」。
AACPOJ 筆記怎麼使用?
AACPOJ 的筆記支援 Markdown + LaTeX 數學式。寫新筆記時,記住這幾個基本規則就好:
- 行內數學使用
$...$,獨立顯示數學使用$$...$$。 ~~...~~是刪除線,只有想把文字劃掉時才使用。- checklist 支援
- [ ]和- [x]。 - 一般筆記請以 Markdown 為主,不要依賴 raw HTML;部分 HTML 會因安全原因被過濾。
- 筆記可見度可以選私人、班級、公開。建議先當私人草稿,整理好再分享。
- 筆記可以選排版風格:普通、紙質、Kindle。普通風格適合公告、指南和短篇整理。
筆記可以記什麼?
以下項目不是每題都要全寫,挑對未來的你最有幫助的就好。
題目簡述(抽象化)
用一兩句話把題目的「數學本質」寫下來,把故事剝掉。例如:
- 不要寫:「有個人要送禮物給朋友……」
- 改成:「給定陣列 \(a\),求最小的 \(k\) 使得 \(\sum a_i \le k\)」
這樣之後掃過筆記能一眼看出是什麼類型的題目。
關鍵觀察 / 性質
這是筆記裡最有價值的部分。 寫下你在解題過程中「想通」的那一刻看到的性質:
- 發現答案一定單調,可以二分搜。
- 注意到 \(k\) 次操作後只有前 \(\log n\) 位會變。
- 把問題轉成圖論:點代表狀態,邊代表轉移。
- 對固定終點 \(r\),最佳左端點 \(l\) 可以用雙指針維護。
思路演進
從樸素解到正解的演進過程,比只寫最終解法更有學習價值。例如:
- 最初想到 \(O(n^2)\) 暴力:每個位置枚舉所有前一個位置。
- 優化 1:發現重複計算,預處理前綴和,降到 \(O(n)\)。
- 優化 2:觀察到單調性,可以用單調佇列,實作更簡潔。
踩過的坑 / 常見錯誤
寫下你這次犯的錯,讓未來不再犯:
- 沒開
long long。 - 二分搜邊界
+1/-1寫錯。 - 陣列開太小。
- 忘記初始化 DP。
- 多筆測資時忘了清空全域陣列。
- 輸出格式少空格或少換行。
下次遇到類似題可以當 checklist 用。
類似題 / 延伸題
當發現這題和某題「套路一樣」時,互相連結起來:
這題和 CF 1234A 一樣是用字典序貪心,核心觀察相同。
也可以連到自己的 AC submission、官方題解、課堂講義或同學整理得很好的公開筆記。
複雜度與標籤
簡短記錄時間/空間複雜度,方便之後判斷題目難度。標籤可以用關鍵字搜尋:#線段樹 #區間DP #圖論 #二分搜。
Markdown 基本語法速查
標題分層
用 ## / ### / #### 分章節,結構清楚:
## 思路
### 關鍵觀察
### 實作細節
不要每一行都用大標題。通常一份筆記只需要幾個二級標題,細節用清單或段落就好。
粗體、斜體、刪除線
**重點文字**、*強調文字*、~~刪除文字~~
顯示為:重點文字、強調文字、刪除文字
項目清單
無序清單用 -:
- 第一點
- 第二點
- 子項目(縮排兩格)
有序清單用 1.:
1. 第一步
2. 第二步
3. 第三步
Checklist
如果你想做解題檢查、待辦事項、複習進度,可以用 checklist:
- [x] 已附上題目連結
- [ ] 檢查邊界條件
- [ ] 補上複雜度分析
顯示為:
- 已附上題目連結
- 檢查邊界條件
- 補上複雜度分析
在自己的筆記閱讀模式中,checkbox 可以拿來追蹤進度;分享給別人看時,通常只是顯示目前狀態。
程式碼
行內程式碼用反引號 `:
`O(n log n)` 的解法
多行程式碼用三個反引號,並一定要標記語言,才會有 syntax highlight:
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
cout << 1LL * n * n << '\n';
return 0;
}
```
常用語言標記:cpp、python、java、markdown。
引用區塊
用 > 放重點觀察、題意摘要、老師提醒:
> 核心觀察:當 $n$ 為偶數時,答案必然存在。
表格
比較兩種做法、列出時間複雜度、對照資料範圍特別好用:
| 方法 | 時間 | 空間 | 備註 |
|---|---|---|---|
| 暴力 | $O(n^2)$ | $O(n)$ | 可過 $n \le 5000$ |
| 線段樹 | $O(n \log n)$ | $O(n)$ | 正解 |
AACPOJ 的表格也支援欄位對齊:
| 預設 | 靠左 | 置中 | 靠右 |
|---|:---|:---:|---:|
| 一般 | left | center | right |
| $O(n)$ | $a_i$ | $x \in S$ | $10^9+7$ |
渲染:
| 預設 | 靠左 | 置中 | 靠右 |
|---|---|---|---|
| 一般 | left | center | right |
| \(O(n)\) | \(a_i\) | \(x \in S\) | \(10^9+7\) |
規則是::--- 靠左、:---: 置中、---: 靠右。沒有加冒號時就是預設對齊。
如果表格裡的內容很長,讀起來通常會比清單更難。這時改用小標題或清單會比較清楚。
連結
[顯示文字](https://example.com)
題目、提交紀錄、官方題解、自己曾經 AC 的 submission,都可以用連結串起來。
水平分隔線
用 --- 隔開章節,讓長筆記有呼吸空間:
---
LaTeX 數學式速查
這一段是主要查表區。想找符號時,優先看「LaTeX 符號總表」;想寫多行公式時,再看後面的 DP、分段式與對齊推導範例。
行內數學與區塊數學
行內數學放在一句話中間,用 $...$:
當 $n \le 10^5$ 時,$O(n \log n)$ 的解法可以通過。
渲染:
當 \(n \le 10^5\) 時,\(O(n \log n)\) 的解法可以通過。
區塊數學獨立一段,用 $$...$$。前後建議空一行:
對於所有 $i$,
$$
\sum_{j=1}^{i} a_j \ge \lfloor \log_2 i \rfloor
$$
這個式子始終成立。
渲染:
對於所有 \(i\),
\[\sum_{j=1}^{i} a_j \ge \lfloor \log_2 i \rfloor\]這個式子始終成立。
如果你只是想在教學中展示 LaTeX 原始碼,請放進程式碼區塊或反引號,例如 `$O(n \log n)$`,才不會被當成公式渲染。
LaTeX 符號總表
以下把競程筆記最常查的符號集中在一起。左欄可以直接複製,右欄確認渲染效果。
符號分類捷徑:變數 / 括號、比較 / 邏輯 / 量詞、運算 / 取整 / 複雜度、求和 / 範圍、圖論 / 集合 / 組合、希臘字母。
變數、上下標、括號
| 想表達 | 原始碼 | 效果 |
|---|---|---|
| 下標 | $a_i$ |
\(a_i\) |
| 多字元下標 | $a_{i,j}$ |
\(a_{i,j}\) |
| 上標 | $a^2$ |
\(a^2\) |
| 多字元上標 | $a^{n+1}$ |
\(a^{n+1}\) |
| DP 狀態 | $dp_i$、$dp_{i,j}$ |
\(dp_i\)、\(dp_{i,j}\) |
| 括號自動變大 | $\left(\frac{a}{b}\right)$ |
\(\left(\frac{a}{b}\right)\) |
| 集合大括號 | $\{a,b,c\}$ |
\(\{a,b,c\}\) |
| 絕對值 | $\lvert x \rvert$ |
\(\lvert x \rvert\) |
比較、邏輯、量詞
| 想表達 | 原始碼 | 效果 |
|---|---|---|
| 小於等於 / 大於等於 | $\le$、$\ge$ |
\(\le\)、\(\ge\) |
| 不等於 | $\neq$ |
\(\neq\) |
| 約等於 | $\approx$ |
\(\approx\) |
| 推導 | $\Rightarrow$ |
\(\Rightarrow\) |
| 等價 | $\Longleftrightarrow$ |
\(\Longleftrightarrow\) |
| 且 / 或 / 非 | $\land$、$\lor$、$\neg$ |
\(\land\)、\(\lor\)、\(\neg\) |
| 對所有 | $\forall i$ |
\(\forall i\) |
| 存在 | $\exists x$ |
\(\exists x\) |
| 屬於 / 不屬於 | $x \in S$、$x \notin S$ |
\(x \in S\)、\(x \notin S\) |
運算、取整、複雜度
| 想表達 | 原始碼 | 效果 |
|---|---|---|
| 乘法點 | $a \cdot b$ |
\(a \cdot b\) |
| 乘號 | $a \times b$ |
\(a \times b\) |
| 取模 | $a \bmod m$ |
\(a \bmod m\) |
| 最小值 / 最大值 | $\min(a,b)$、$\max(a,b)$ |
\(\min(a,b)\)、\(\max(a,b)\) |
| 分數 | $\frac{a}{b}$ |
\(\frac{a}{b}\) |
| 開根號 | $\sqrt{n}$ |
\(\sqrt{n}\) |
| 對數 | $\log n$、$\log_2 n$ |
\(\log n\)、\(\log_2 n\) |
| 向下取整 | $\lfloor x \rfloor$ |
\(\lfloor x \rfloor\) |
| 向上取整 | $\lceil x \rceil$ |
\(\lceil x \rceil\) |
| 複雜度 | $O(n \log n)$ |
\(O(n \log n)\) |
| 十的五次方 | $10^5$ |
\(10^5\) |
| 二乘十的五次方 | $2 \times 10^5$ |
\(2 \times 10^5\) |
| 常見模數 | $10^9+7$、$998244353$ |
\(10^9+7\)、\(998244353\) |
求和、乘積、範圍
| 想表達 | 原始碼 | 效果 |
|---|---|---|
| 求和 | $\sum_{i=1}^{n} a_i$ |
\(\sum_{i=1}^{n} a_i\) |
| 求積 | $\prod_{i=1}^{n} a_i$ |
\(\prod_{i=1}^{n} a_i\) |
| 閉區間 | $[1,n]$ |
\([1,n]\) |
| 半開區間 | $(l,r]$ |
\((l,r]\) |
| 整數範圍 | $1 \le n \le 2 \times 10^5$ |
\(1 \le n \le 2 \times 10^5\) |
| 陣列元素範圍 | $0 \le a_i < 10^9+7$ |
\(0 \le a_i < 10^9+7\) |
圖論、集合、組合
| 想表達 | 原始碼 | 效果 |
|---|---|---|
| 圖 | $G=(V,E)$ |
\(G=(V,E)\) |
| 邊屬於圖 | $(u,v) \in E$ |
\((u,v) \in E\) |
| 距離陣列 | $dist_s[v]$ |
\(dist_s[v]\) |
| 度數 | $\deg(v)$ |
\(\deg(v)\) |
| 最短路鬆弛 | $dist[v] > dist[u] + w$ |
\(dist[v] > dist[u] + w\) |
| 子集 | $A \subseteq B$ |
\(A \subseteq B\) |
| 真子集 | $A \subset B$ |
\(A \subset B\) |
| 聯集 / 交集 | $A \cup B$、$A \cap B$ |
\(A \cup B\)、\(A \cap B\) |
| 空集合 | $\emptyset$ |
\(\emptyset\) |
| 組合數 | $\binom{n}{k}$ |
\(\binom{n}{k}\) |
常用希臘字母
| 想表達 | 原始碼 | 效果 |
|---|---|---|
| alpha / beta | $\alpha$、$\beta$ |
\(\alpha\)、\(\beta\) |
| gamma / delta | $\gamma$、$\delta$ |
\(\gamma\)、\(\delta\) |
| epsilon | $\epsilon$、$\varepsilon$ |
\(\epsilon\)、\(\varepsilon\) |
| theta | $\theta$、$\Theta$ |
\(\theta\)、\(\Theta\) |
DP / 遞迴式 / 分段式
DP 轉移式適合用區塊數學,閱讀上會比塞在一行內清楚:
$$
dp_i = \min_{0 \le j < i} (dp_j + cost(j+1, i))
$$
渲染:
\[dp_i = \min_{0 \le j < i} (dp_j + cost(j+1, i))\]分段式可以用 cases:
$$
dp_i =
\begin{cases}
0, & i = 0 \\
dp_{i-1} + a_i, & i > 0
\end{cases}
$$
渲染:
\[dp_i = \begin{cases} 0, & i = 0 \\ dp_{i-1} + a_i, & i > 0 \end{cases}\]對齊推導
如果你要寫多行推導,可以用 aligned:
$$
\begin{aligned}
\sum_{i=1}^{n} i
&= 1 + 2 + \cdots + n \\
&= \frac{n(n+1)}{2}
\end{aligned}
$$
渲染:
\[\begin{aligned} \sum_{i=1}^{n} i &= 1 + 2 + \cdots + n \\ &= \frac{n(n+1)}{2} \end{aligned}\]& 是對齊位置,通常放在等號前。換行用 \\。
LaTeX 常見錯誤
- 忘記結尾
$:$O(n log n)會讓後面的文字都可能被當成公式。 - 在公式外直接寫
_:請改成$a_i$,不要寫a_i。 - 在公式中寫中文句子:通常把中文放在公式外,公式只放變數和符號。
- 大括號要顯示時要跳脫:寫
$\{1,2,3\}$,不是${1,2,3}$。 - 絕對值建議寫
$\lvert x \rvert$,比$|x|$更不容易和表格分隔線混淆。 - 區塊公式前後沒有空行時,比較容易和段落黏在一起。
- 公式太長時不要硬塞行內,改用
$$...$$。 - 只想展示原始碼時,要放進 code block,不然會被渲染掉。
分享、排版與預覽
可見度
筆記預設建議先當私人草稿。整理好之後,可以視情況調整:
- 私人:只有自己看得到,適合草稿、未整理想法、錯誤紀錄。
- 班級:指定班級可看。通常用於課程內共享資料或老師整理的筆記。
- 公開:登入使用者皆可看,適合整理完整、可給同學參考的內容。
公開或分享前,請檢查不要放入帳號密碼、私人資訊、未授權轉貼內容。
排版風格
筆記可以選不同風格:
- 普通:白底簡潔,適合公告、指南、短篇整理。
- 紙質:米色暖調,適合學習筆記、解題心得。
- Kindle:灰調極簡,適合長篇閱讀。
排版風格只改變閱讀體驗,不會改變 Markdown 原始內容。
預覽
編輯器有「編輯 / 分割 / 預覽」模式。建議至少在儲存前看一次預覽,特別確認:
- 目錄連結能不能跳到正確章節。
- 數學公式有沒有正確顯示。
- 程式碼區塊有沒有標記語言並正確 highlight。
- 表格有沒有對齊。
- checklist 有沒有變成 checkbox。
- 標題層級有沒有混亂。
- 連結是否能正常打開。
一份好筆記的範例
以下是一個理想筆記的骨架。你可以直接照這個順序寫,再依題目刪減。
## 題目簡述
給定長度 $n$ 的陣列,求最小化……
## 資料範圍
- $1 \le n \le 2 \times 10^5$
- $1 \le a_i \le 10^9$
## 關鍵觀察
1. 答案對 $k$ 具有單調性,可以二分搜。
2. 對於固定的 $k$,判斷可行性只需要一次線性掃描。
## 思路演進
- **暴力**:枚舉所有 $k$,$O(n^2)$,會 TLE。
- **優化**:二分搜 + 線性 check,變成 $O(n \log n)$。
## 實作細節
- 二分搜範圍:`[1, max(a)]`
- `valid(k)` 函數:……
## 踩過的坑
- [x] 一開始把二分搜的邊界寫成 `l = mid`,導致 TLE。
- [x] 沒開 `long long`,累加時 overflow。
- [ ] 下次重寫前先檢查 `valid(k)` 的單調方向。
## 複雜度
- 時間:$O(n \log V)$
- 空間:$O(n)$
## 核心程式碼
```cpp
bool valid(long long k) {
// ...
}
int main() {
long long lo = 1, hi = 1000000000LL;
while (lo < hi) {
long long mid = (lo + hi) / 2;
if (valid(mid)) hi = mid;
else lo = mid + 1;
}
cout << lo << '\n';
}
```
## 類似題
- CF 1234A(同樣的二分搜套路)
- ABC 321D(延伸:加上 DP)
標籤:`#二分搜` `#貪心`
小結
寫筆記的第一條準則:為了未來的自己寫。
記錄關鍵觀察、思路演進、踩過的坑,比抄下一份標解更有價值。再搭配 Markdown 的標題、清單、checklist、程式碼區塊、LaTeX 數學公式,就能做出一份回頭看依然能幫你重新理解題目的好筆記。