Houses - MarisaOJ: Marisa Online Judge

Houses

Time limit: 1000 ms
Memory limit: 256 MB
The city government wants to build houses on a street. At each moment, a house will either be built or demolished at a specific location. After each house is built or demolished, if there are at least two houses on the street, the government wants to find the minimum distance between any two different houses. ### Input - The first line contains an integer $n$, the number of times houses are built/demolished. - The next $n$ lines each contain an integer $p$, a location. If there is currently no house at location $p$, then build a house here; otherwise, demolish the existing house. ### Output - Print $n$ lines, after each house is built/demolished, print the minimum distance between any two houses. If there are not at least two houses, print `-1`. ### Constraints - $1 \le n \le 10^5$. - $1 \le p \le 10^9$. ### Example Input: ``` 5 1 3 2 2 3 ``` Output: ``` -1 2 1 2 -1 ```