IOI 2004 - Empodia
Author: Benjamin Qi
Let denote the input sequence. An interval is framed if all three of the following conditions hold:
Our approach will be to iterate over all and check whether contributes a new empodio with right endpoint .
- Maintain a stack consisting of all indices satisfying the second condition.
- When we increment , repeatedly pop the top element of while . Then add to .
- To check whether is part of an empodio, find the maximum such that . If is to the right of the rightmost left endpoint of any empodio found so far and , then we have found a new empodio.
To check whether , we can maintain a separate stack that stores all indices such that .
Note: The test data on Yandex has sequences of length greater than
const int BIG = 3000000;vi stor[2*BIG];int N;vi v;int dif(int x) { return v[x]-x+N; } // add N so difference is non-negativeint main() {setIO(); re(N); v.rsz(N); re(v);vi mn, mx;