Kacam.net

Algorithms

前缀和能用的前提是可逆

区间和能用它,区间最大值不能 —— 那条界线在哪?

Copy the prompt, then pick a model. It plays the interviewer and asks you through it scene by scene instead of handing you the answer.

On a phone with the app installed, the system opens the app directly. Links cannot open external apps inside WeChat — open it in a browser first.

The copied text ends with the answer key the model grades you against. Don't read it yourself first — working it out on your own is the point.

这东西看起来简单到不值得练,但一多半人说不出它凭什么成立。答案是可逆:加法有减法能撤销,所以能用;max 没有,所以照套就错。

第三幕把差分引出来,它是前缀和的逆运算 —— 前缀和把区间查询变成两次单点访问,差分把区间修改变成两次单点修改。中间要查怎么办?那就是另一个结构的事了。

顺带治两个高频 off-by-one:前缀和数组为什么多留一位、哈希表为什么要先放一个 0。

★★★☆☆ · about 30 min · Tests: 可逆性这个前提、差分是它的逆、下标偏移、离线

What this one drills

Invariants Boundary conditions Choosing a structure

Have you done this one?

Sign in to mark this one as practised — next time you come back you'll see when you did it.

Notes from people who did this one

Nobody has written yet. After you run it, say what came out of the conversation — which scene stumped you, which conclusion you changed afterwards.

Sign in to write a note.

How to use this

This set teaches rather than interrogates: it guides you instead of pressing until you have nothing left to say. When you're stuck it first asks which layer you're stuck at (never heard of it / know it but not why / know why but can't write it), then decides what to give. Only after guiding you twice on the same point will it spell the answer out — and then it asks you to say it back in your own words.

How to start

  1. Pick one, open it, copy the prompt.
  2. Paste it into a brand-new conversation, say nothing, and wait for its first question.
  3. Trace by hand before you write code — it will interrupt you. Walking through an array of length 2 beats writing the template ten times.

Four commands you can call out at any time

  • 跳过 move to the next scene now
  • 换个说法 explain this bit again from another angle
  • 直说吧 spell the answer out, then make me say it back
  • 复盘 jump to the wrap-up and print the review card

Three traps

  • Don't read the answer key at the end first — that "how people get it wrong" section is the answer to every question it will ask you.
  • Don't rush to code. With algorithms, writing code is the easiest way to hide the fact that you haven't actually thought it through.
  • When it starts praising you, point it back to the "don't praise me" rule. Guiding is not coddling.

Can't come up with a solution? Start with defining the DP state. Always off by one? Binary search and prefix sums. Can't recognise the shape of a problem? Monotonic stack and sliding window. The complexity one underpins several others — do it early.