Skip to main content

Checkpoint: The Living Maximum

Challenge on lesson: Checkpoint — The Living Maximum

CHALLENGE
Difficulty: advanced+25 XP

**Task.** An array of n values. q operations: 1 p x sets a[p] = x; 2 l r asks the maximum of a[l..r] (inclusive, 0-indexed). After all operations, print the XOR of every answer from type-2 operations. **Constraints:** 1 ≤ n, q ≤ 200000; 0 ≤ a[i], x < 10^6; 0 ≤ l ≤ r < n. **Budget check:** interleaved updates kill static prefixes; the named bottleneck is 'range max that changes' → segment tree, O((n + q) log n). The naive rescan is O(n·q) ≈ 4·10^10 — dead.

Back to lesson: Checkpoint — The Living Maximum