Hello there
I'm trying to solve this problem
I've thought alot about it and have no idea
Any clues would be appreciated
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Hello there
I'm trying to solve this problem
I've thought alot about it and have no idea
Any clues would be appreciated
Название |
---|
google static case, i.e. longest alternating subsequence problem. You will find several approaches, one of them is compatible with data structures like segment tree or sqrt decomposition. It's a bit tricky though
...ok, my submission received WA29, I believe it's just a minor bug, don't like these paperworks
The approach being to count the number of peaks (ai - 1 < ai > ai + 1 or ai - 1 > ai < ai + 1).
The real tricky part is dealing with groups of adjacent equal numbers, because you need to treat them as if they were a single number. I don't remember exactly how I did it, but I think it involved a few BITs to keep track of where each group starts. There's probably something simpler...
EDIT: You should be able to do it with a single segment tree if you keep in each node whether the last change was increasing or decreasing (along with the number of peaks). Shouldn't have too many special cases. (Idea taken from desperado123)
thanks a lot
counting number of peaks never occurred to me ... will try to apply with a segment tree like you said
use binary indexed tree