hiroshima_boy's blog

By hiroshima_boy, history, 4 years ago, In English

1.) __builtin_popcount(x): Counts the number of one’s(set bits) in an integer(long/long long).

Ex- int x=5;
    cout<<__builtin_popcount(x)<<endl;   //returns 2.

If x is of long type,we can use __builtin_popcountl(x) If x is of long long type,we can use __builtin_popcountll(x)

2.) __builtin_parity(x): Checks the Parity of a number.Returns true(1) if the number has odd parity(odd number of set bits) else it returns false(0) for even parity(even number of set bits).

Ex- int x=5;
    cout<<__builtin_parity(x)<<endl;   //returns 0.

If x is of long type,we can use __builtin_parityl(x) If x is of long long type,we can use __builtin_parityll(x)

3.) __builtin_clz(x): Counts the leading number of zeros of the integer(long/long long).

If x is of long type,we can use __builtin_clzl(x) If x is of long long type,we can use __builtin_clzll(x)

Ex- int x=16;       // 00000000 00000000 00000000 00010000 (32 bits)
      cout<<__builtin_clz(x)<<endl;   //returns 27.

  Ex- long x=16;       // 00000000 00000000 00000000 00010000 (32 bits)
      cout<<__builtin_clzl(x)<<endl;   //returns 27.

  Ex- long long x=16;       // 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00010000 (64 bits)
      cout<<__builtin_clzll(x)<<endl;   //returns 59.

4.) __builtin_ctz(x): Counts the trailing number of zeros of the integer(long/long long).

If x is of long type,we can use __builtin_ctzl(x) If x is of long long type,we can use __builtin_ctzll(x)

Ex- int x=16;       // 00000000 00000000 00000000 00010000 (32 bits)
    cout<<__builtin_ctz(x)<<endl;   //returns 4.

In case of both __builtin_ctzl(x) and __builtin_ctzll(x),the answer is same.

Full text and comments »

  • Vote: I like it
  • +7
  • Vote: I do not like it

By hiroshima_boy, history, 4 years ago, In English

I don't have the exact question link which directs us implement this idea but I have an abstract.

Two arrays containing distinct(unique) elements are given . We have to delete minimum number of elements from both the arrays such that a strictly increasing sequence of length 4 does not exist. Provided a Sequence is made by alternately taking elements from the arrays.

Arrays contain only the elements from [1,array1.length+array2.length]

Full text and comments »

  • Vote: I like it
  • +12
  • Vote: I do not like it