Siriuslight's blog

By Siriuslight, history, 6 years ago, In English

I have started learning JAVA recently. I wrote a code for this problem.

Reference to my code is here.

I can't find out why it is giving me TLE. Can someone help out?

UPD : I found the problem. I needed to keep 1 << 20 in parenthesis.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Siriuslight, history, 6 years ago, In English

I have seen these lines in codes of various people. People use it for debugging. Can someone please explain how it works?

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

Full text and comments »

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

By Siriuslight, history, 6 years ago, In English

How to solve this problem using matrix exponentiation. The recurrence relation is :

f(n, k, 0) = 2 * f(n - 1, k, 1) + f(n - 1, k, 0)

f(n, k, 1) = f(n - 1, k, 1) + f(n - 1, k, 0)

1 < n < 1e9

1 < k < 1e3

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Siriuslight, history, 6 years ago, In English

I implemented a code for Problem 55 of Project Euler. It is giving me an incorrect answer. This my code.

Can anyone help me, to find the bug?

THOSE WHO DID NOT SOLVE IT, PLEASE DO NOT OPEN THE CODE. IT WILL BE A SPOILER.

Full text and comments »

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

By Siriuslight, history, 6 years ago, In English

If I want to implement trie using two dimensional array, how should I decide the size of array.

Full text and comments »

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

By Siriuslight, history, 7 years ago, In English

I have implemented 903D using Mergesort Tree and maintaining a prefix sum vector for every vector of merge sort tree.

For every a[i], I am calculating the sum of all a[j], where a[j] > a[i]+1 or a[j] < a[i]-1, j < i. Using this sum I am subtracting this sum from answer and adding a[i], same number of times.

My submission. This error is because of integer overflow, but when I change all integers to long long. It gives me wrong answer.

Any help would be appreciated. :)

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Siriuslight, history, 7 years ago, In English

I think some will agree with my opinions and some might feel it is not necessary in Competitive Programming. But, I feel that programming is not just about writing a correct a code that solves the purpose, but also how the code looks.

Everyone have their own style of writing codes. One of the persons whom I admire the most is rajat1603(Rajat De). Rajat's codes are very well formatted and obviously they are correct. I think the people who are learning from reading other's code get benefited from these beautiful codes a lot. I personally feel very happy after seeing Rajat's code. There are also various other coders who code beautifully like our legendary champion tourist(Gennady Korotkevich).

I just want to advice everyone to write your codes like its your personal signature, follow your own style and maintain a symmetry. Try it, feels good. I am not a very good problem solver neither a good blogger. I just love beautiful codes.

Please give suggestions, how this can be encouraged.

  • Extra points can be awarded if possible during contests.
  • A new rating like contribution and contests rating for code beauty.

Full text and comments »

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

By Siriuslight, history, 7 years ago, In English

I have seen two implentation of DFS that people generally use.

bool visit[N];
int par[N];
vector<int> g[N];
void dfs1(int v)
{
    visit[v] = true;
    for(auto child : g[v])
    {
         if(!visit[child])
              dfs1(child);
    }

}

void dfs2(int v, int p)
{
    par[v] = p;
    for(auto child : g[v])
    {
          if(child == par[v])
                continue;
          dfs(child,v);
    }

}

What is the difference between these two implementations? Is the second implementation only used when we need parent or some other cases also. I always maintain visit array, but some people don't does it affect. I think it should cause infinite recursion but it doesn't.

Can someone please explain it in details.

Full text and comments »

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

By Siriuslight, history, 7 years ago, In English

I am little confused on time complexity of a query in sparse table. I got conflicting answers from two sources. On hackerearth O(logn) (link) is mentioned and on geeksforgeeks O(1) (link) is mentioned.

Can anyone tell me the correct time complexity?

Full text and comments »

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

By Siriuslight, history, 8 years ago, In English

Can this problem problem be solved using segment tree. If yes can anyone can tell how to build Seg tree.

During combining two segments how do i check for mid and (mid+1)th element in merged segement.

Full text and comments »

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

By Siriuslight, history, 8 years ago, In English

Some people have done k=k%1024, I don't understand why? Can someone tell me.

Problem link here.

Full text and comments »

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

By Siriuslight, history, 8 years ago, In English
  • Vote: I like it
  • -1
  • Vote: I do not like it

By Siriuslight, history, 8 years ago, In English

Hello to Codeforces community. This not like I want to share some of my knowledge. Its just a request for some experienced coders to give some information regarding their journey on codeforces. Beginning from their coding life as a low level coder to becoming red or orange coders. It will give a lot of inspirition to inexperienced coders like us. I would be delighted and thankful to them who would share their experiences.

Full text and comments »

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