I was solving this problem. I have a function go, which returns a boolean true or false. When I replace "|" with "||", I get AC, otherwise I get TLE on test 6. I get AC with "||" and "or", but TLE with "|". Can anyone tell me the difference between the three?









For booleans there is priority difference: http://en.cppreference.com/w/cpp/language/operator_precedence
Can you show your code? Possibly you use '|' and '&&' combination.
AC Code
TLE Code
Look in the last line of go function.
| is bitwise operator.
|| and "or" are logical operator.
As tyamgin said it could happen because of precedence.
"The & and | operators have lower precedence than comparison operators. That means that x & 3 == 1 is interpreted as x & (3 == 1), which is probably not what you want." Source
Thanks!
First of all,
||andorare identical, but there is a big difference between|and||.||is a boolean operator.a || breturnstrueorfalse. Ifais non-zero, then the value ofbis not checked (since the answer is guaranteed to betrue).|is bitwise-or.a | breturns a number (which can then be cast to a boolean if you need to). This evaluates bothaandb, and then computes the bitwise or of them.The most likely reason that
||is not getting TLE is because it is not evaluating the second operand. This is especially true if the second operand is a complex function that has to be evaluated.