hellomoto's blog

By hellomoto, history, 8 months ago, In English

As we know if we have an array of size n, let's say a0, a1, a2, ......, an-1. we can preform x move clockwise with ((ai + x) % n) and anticlockwise with ((ai — x) % n + n) % n.

Can we generalized for clockwise and anticlockwise for the index i to j (0 <= i, j < n)?

So what will be the formula if we want to move x (x can be greater than (j — i + 1)) steps in a circle from ai to aj (0 <= i, j < n) in an array (0 indexed and size of the array is n)?

Any help will be appreciated.

Read more »

 
 
 
 
  • Vote: I like it
  • -22
  • Vote: I do not like it

By hellomoto, history, 3 years ago, In English

How internally upper_bound for sorted vector(in ascending order) works in c++. Let say 'A' is a sorted vector.Then how upper_bound(A.begin(),A.end(),x) will directly give iterator to first element greater than x. Thanks in advance.

Read more »

 
 
 
 
  • Vote: I like it
  • -11
  • Vote: I do not like it

By hellomoto, history, 3 years ago, In English

if(1<=A[i]<=2*1e9)

vector<long long int>A;
auto it=upper_bound(A.begin(),A.end(),1000000000);

is it overflows? why it is giving wrong answer for me in c++.

Read more »

 
 
 
 
  • Vote: I like it
  • -19
  • Vote: I do not like it