Can't find any announcement for ACL Beginner Contest, so creating this to discuss problems.
Answer is number of connected components — 1
For each value a[i], Use segment tree to find maximum length from 1 to a[i] — k and a[i] to a[i] + k. After that update a[i] to that length.
How to solve E?
I tried to make 9 segment tree for each 1 — 9 digits but couldn't find how to do update query where setting everything between l to r to zero when removing digit and to one when adding it.