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
#include <bits/stdc++.h>using namespace std;using ll = long long;using ld = long double;using db = double;using str = string; // yay python!using pi = pair<int, int>;using pl = pair<ll, ll>;
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!