aneee's blog

By aneee, history, 4 years ago, In English

Problem.

I solved the problem with three pointers. But when I sort the vectors first and the resize, I get an AC. If I sort them after making them unique, I get a WA.

AC Code
WA Code
  • Vote: I like it
  • -14
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it +47 Vote: I do not like it

Unique requires the vector to be sorted. All it does is check if adjacent elements are equal.

»
4 years ago, # |
  Vote: I like it +31 Vote: I do not like it

unique only causes consecutive groups of identical elements to be condensed. So you need to sort first.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you! So I guess there is no way to extract unique elements, maintaining the given order?

    ^ using an std algorithm I mean.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      In a way, you can. For instance if you do unique on the array

      5 5 5 0 0 1 0 0 2 2 5 5 5 5 5
      

      you would get

      5 0 1 0 2 5.