Is there a difference in time between the two methods? Which one is better and why?
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3382 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 134 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
Is there a difference in time between the two methods? Which one is better and why?
| Name |
|---|



There is no difference in time, but using
#define ll long longis not recommended by specifications, you should usetypedeffor defining types.or try
It's easier to understand! Though I always end up using
#definebecause of my bad practices :(Neither define nor typedef defines a new type.
The syntax
using ll = long long;is more modern.For a simple type definition it does exactly the same as
typedef long long ll;But
usingsupports template parameters, so the concept is more powerful. In example the following definition does not work good with typedef.Since a typedef does not support template parameters we would need to 'misuse' a struct, something like this:
Thanks! But which one would you recommend?
Until some hours ago I used typedef, then did read your post, did read about the topic...and decided to use using.
Thanks for the help!
Both of these are wrong. Use #define int long long =)
Why int long long is bad? (I don't know)
Well sometimes it causes TLE because the processing time for long long is 2 times that of int and the statement changes all
inttolong long, so after continuous use of#define int long longyou kind of forget that it's there, and with problems with tight time limit bound you end up getting a TLE ( but after 1 or 2 TLE's you kind of become vigilante :p )thanks to reply
A lot of simple 64-bit operations are one clock cycle if you submit with C++17 (64). In the time I've used
#define int long longin my template, it hasn't caused me any trouble in MLE/TLE, and has saved me many times from unexpected overflow.Well you can't expect every website to be as upto date as CF, even Google competitions don't have c++17 as far as I remember :)
remember to write
signed main()int32_talso worksEven if they execute in 1 clock cycle it still affects the amount of data that fits in your cache, which could be a problem in problems with tight time limits.
Another reason it is bad is that you can forget that you are using
long longs, which could cause you to useINT_MAXinstead ofLLONG_MAXfor exampleprint
long longmanually until you're masterUse
using ll = long long.It will replace
llwithlong longonly in contexts wherellis a type. It also makes a real type-level type alias.#define ll long longwill blindly replacelltoken withlong longtokens everywhere in your code even if it does not make sense. In particular, you won't be able to writell(10.5)with#defineas you could with other types likeint(10.5).