Fix the right end at r and ask: how many starts make a valid substring? A substring [s..r] contains an a, a b and a c exactly when it reaches back past the most recent occurrence of all three — so keep last[a], last[b], last[c] and take m = min(last). Every start s ≤ m works and every start s > m misses whichever character sits at m, so the step banks exactly m + 1. That minimum is not a helper value — it is the left boundary of the answer, which is why the page draws it as the pivot. The shrinking-window formulation works too: hold l, advance it while [l..r] still contains all three, then add l — and it lands on the same number, because that l ends up equal to m + 1. It is just more fragile: it needs a frequency map with matching increments and decrements, an inner loop, and a decision about whether to add before or after shrinking. The last-occurrence form has none of those, and the −1 sentinel makes the "not all three seen yet" case fall out of the arithmetic on its own — m = −1 adds 0, so there is no special case to forget.
count, and every substring is counted exactly once —
at the step where its right end is reached. The whole problem reduces to
count += min(last[a], last[b], last[c]) + 1.