掌握 sort unique lower_bound 用法
sort
unique
lower_bound
1 20 300 4000
1 2 3 4
离散化
discreting
离散化
5
400 200 200 300 100
4 2 2 3 1
100 200 300 400
^
unique 之前 1 1 0 0 1 1 0 0
unique 之后 1 0 1 0
下标 0 1 2 3 4 返回值=指向4的指针
unique 之前 1 1 1 2 2 2 3 3
unique 之后 1 2 3
下标 0 1 2 3 返回值=指向3的指针
upper_bound(aa, aa + ac, x) - lower_bound(aa, aa + ac, x)
问数组 aa, aa + ac 中,x出现的次数
lower_bound(a.begin(), a.end(), x) vector a 中 >= x 最小的位置
upper_bound(a.begin(), a.end(), x) vector a 中 > x 最小的位置
对于整数来说 > x 等价于 >= x + 1
upper_bound(a.begin(), a.end(), x) == lower_bound(a.begin(), a.end(), x + 1)
1 1 1 2 2 2 3 3
^ upper_bound 寻找 2
^ lower_bound 寻找 2
upper_bound - lower_bound == 3 就是 2 的出现次数
abc213_c Reorder Cards
https://atcoder.jp/contests/abc213/tasks/abc213_c