Keep it simple
OMDG it took me longer to work out what your code was doing than to write a solution.
Some of it seams to have taken the most complex possible path to a solution, and I am still not 100% sure (as I gave up deciphering that code) what the buf_get_with_leading_space means with leading_space. I am assuming you mean leading off bits?
I get the ...
#pragma GCC optimize("O2")
Normally we just pass that as a compiler flag, so we don't get "unrecognised pragma" warnings from other compilers.
long int c,d,j,N,Q;
These are poor names - they tell us very little about what they are used for.
The number of array elements and the number of queries can't be negative. I suggest ...
Here are some things that may help you improve your code.
Choose better variable names
I understand that N and Q are used within the problem description, but c and d are not and are very short and non-descriptive names.
Comments do not add to compile time and help you (and others!) keep track of what is happening in the code.
Add error checking
I see that you've already asked a separate question for the helper functions here, and others have already done a fine job answering it, so I won't add anything to it here. The rewrite I came up with will use a variation of the helper functions that operate directly on the byte array as defined below - this isn't necessary, but I felt these ...
Use proper types
One of the best things you can do to make C++ code better and—usually—faster (either compiling faster, running faster, or both) is to make proper types. C++ is a strongly-typed language, probably the most strongly-type language in popular use. Lean into that. Take advantage of it. Reap the rewards.
Your program is ...
Your code is well done and shows familiarity with Rust.
The best I can do is comment on some parts of the code and provide two small, concrete pieces of advice. There is very little room for improvement in the code.
I see your Vecs in function parameters are well motivated. The one in find_triple is motivated by the need to do pop, and the one in find_pair ...