6
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 ...
3
Code
#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 ...
2
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.
Add comments
Comments do not add to compile time and help you (and others!) keep track of what is happening in the code.
Add error checking
...
2
Helper Functions
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 ...
2
General advice
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.
For example…
Your program is ...
1
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 ...
Only top voted, non community-wiki answers of a minimum length are eligible
Related Tags
algorithm × 4558java × 1209
python × 1069
performance × 895
c++ × 736
programming-challenge × 627
javascript × 432
c# × 374
strings × 326
sorting × 300
beginner × 288
python-3.x × 286
c × 263
graph × 227
time-limit-exceeded × 222
array × 209
tree × 207
python-2.x × 167
recursion × 161
interview-questions × 158
complexity × 123
combinatorics × 116
c++11 × 100
mathematics × 91
matrix × 88