CVOTE - Editorial

pretty cool! :slight_smile:

It is a standard concept in C++ to include left end of the range but not include right end.

So range [0,N-1] is represented as [0,N)

You did not output anything for the test where N=10000 and M=1.

Try some simpler version like
2 1
a b
c d

1 Like

The reason is that unique works correctly only for sorted array.
When you do unique(a,a+8) the content of a[] becomes
a[] = {1,2,3,4,5,6,5,6}
since he stores all unique elements in the beginning but not touch the remaining ones.

When you do unique(a,a+8) twice second time is applied to bad array {1,2,3,4,5,6,5,6}.
Actually unique delete only repetitions of consecutive equal elements.
Hence he consider this array as having all unique elements and returns pointer a+8

Okay, but why are the last three elements 6,5,6 and why not 4,5,6?
Since the unique elements brought forwards should have made the arr[] as {1,2,3,4,5,4,5,6} from my point of view. My question is: why {1,2,3,4,5,6,5,6} any mechanism for that?

Oops, is it due to the a[cN++] = a[i] part that you wrote in the earlier “longer” version that you mentioned in comment to my last answer?

Yes, exactly. But try to output array after unique to make sure that I’m right.

Yes, you were right. Thanks. Nothing else beats the joy of learning something new everyday.

lower_bound behaves like binary search and has complexity O(log N).
O(N) equivalent for basic types is

lower_bound(int* L, int* R, int val) {
    int* i = L;
    for (; i < R && *i < val; ++i);
    return i;

It works correctly only if array is sorted.

Refer to this for exact equivalent raw code:

Will you please refer me to any book or online stuff where I can learn more about STL and functions common in practice in C++, along with their explanations?

Actually I always google function_name C++ reference and appear on the corresponding page at this site.

Thanks Anton, you are the man. One ctrl+z wreaked havoc for me :frowning:

Please indent your code properly. It is very hard to follow it.

Also I see some double loops like for each vote you traverse the list of all chefs to find the proper one.

Such solution will get TLE after you fix the bug that leads to WA.

Which compiler?

Can someone pls explain me if ‘India’ is greater or ‘Indiaa’ ? And how to handle this case using compareTo function?

Why i am getting a WA . Please help. @anton_lunyo

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Can Anyone Have time to review my submission and tell me where My solution gets wrong? Pleaseeeeeeeeeeee

Consider the test input:

3 4
aa Aba

Thanks for your time.
I understood what i am missing.

1 Like