question link : https://mirror.codeforces.com/problemset/problem/1256/B solution link : https://ideone.com/JInG1y What is the problem in this anyone?
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3885 |
3 | jqdai0815 | 3682 |
4 | Benq | 3580 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3506 |
7 | ecnerwala | 3505 |
8 | Radewoosh | 3457 |
9 | Kevin114514 | 3377 |
10 | gamegame | 3374 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 170 |
2 | Um_nik | 162 |
3 | atcoder_official | 161 |
4 | maomao90 | 158 |
4 | -is-this-fft- | 158 |
6 | djm03178 | 157 |
7 | Dominater069 | 156 |
8 | adamant | 154 |
9 | luogu_official | 153 |
10 | awoo | 152 |
question link : https://mirror.codeforces.com/problemset/problem/1256/B solution link : https://ideone.com/JInG1y What is the problem in this anyone?
Название |
---|
could you elaborate on how your code is supposed to work ??
start from 1 if in correct position continue otherwise found its position and while its not in its correct position and swap is possible i keep on swapping.
more specifically what is the map <ll, ll> h doing ??
nevermind this
consider the test case: 1 8 8 5 6 7 1 3 2 4
you code gives: 1 8 5 6 2 7 4 3
ans 1 8 5 6 2 7 3 4
Your code is swapping them before assigning right cnt,
swap(a[e],a[e-1]);
cnt[a[e]]=e-1;
cnt[a[e-1]]=e;
First update then swapcnt[a[e]]=e-1;cnt[a[e-1]]=e;swap(a[e],a[e-1]);
then second thing if say a[e] is 4 and a[e-1] is 3, then you should not swap... eg take this case: n=8, arr=[8 5 6 7 1 3 2 4] after some steps it becomes 1 8 5 6 2 7 3 4, we cannot swap 3 with 7 as that operation is already used, then your code is swapping 4 with 3, hence it gives 1 8 5 6 2 7 4 3. add a conditionwhile(e>i && a[e-1]>a[e] && h.count(e-1)==0)