### Siriuslight's blog

By Siriuslight, history, 4 years ago,

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.

• 0

By Siriuslight, history, 4 years ago,

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


• +1

By Siriuslight, history, 4 years ago,

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

• 0

By Siriuslight, history, 5 years ago,

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.

• -18

By Siriuslight, history, 5 years ago,

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

• +3

By Siriuslight, history, 5 years ago,

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. :)

• 0

By Siriuslight, history, 5 years ago,

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.

• -16

By Siriuslight, history, 5 years ago,

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.

• +2

By Siriuslight, history, 5 years ago,

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?

• -6

By Siriuslight, history, 6 years ago,

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.

• +6

By Siriuslight, history, 6 years ago,

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

• +6

By Siriuslight, history, 6 years ago,

• -1

By Siriuslight, history, 6 years ago,

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.

• +62