Prolem — URL : https://mirror.codeforces.com/contest/223/problem/B. Thanks for reading my stupid blog
Prolem — URL : https://mirror.codeforces.com/contest/223/problem/B. Thanks for reading my stupid blog
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 147 |
| 4 | Proof_by_QED | 146 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 141 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
| Название |
|---|



You want every character in $$$s$$$ to be part of at least one subsequence, instead of trying to find every subsequence and then see if any are good, you can find intervals and if the position is in any interval then it is part of at least one subsequence.
How do we find such intervals ?
Let's look at an example : $$$s$$$ = abadbcd $$$t$$$ = abcd
After out first iteration we will have the values : a = [0, ] b = [1, ] c = [5, ] d = [6, ]
After out second iteration we will have the values : a = [, 2] b = [, 4] c = [, 5] d = [, 6]
Now we combine them and have the intervals : a = [0, 2] b = [1, 4] c = [5, 5] d = [6, 6]
Now we can iterate through all the letters in $$$s$$$ and check if they are in the interval.
The problem with this approach is that it only works for any $$$t$$$ that contains no duplicates.
For the input $$$s$$$ = ababa $$$t$$$ = abba this will fail because the 'a' at index 2 cannot be part of any subsequence but still appears in our interval.
To solve this problem we have to differentiate between the 'a' at position 0 in $$$t$$$ and the 'a' at position 3 in $$$t$$$. We do this by holding an array of intervals for each letter instead of a big interval for each one.
Interval for 'a': Before -> [0,4] After -> $$$[0,0]\cup[4,4]$$$, which now allows us to find the correct answer for all inputs.
After finding all intervals for each letter we can flatten them on a vector for each character in the alphabet.