Is there a difference in time between the two methods? Which one is better and why?
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Is there a difference in time between the two methods? Which one is better and why?
Название |
---|
There is no difference in time, but using
#define ll long long
is not recommended by specifications, you should usetypedef
for defining types.or try
It's easier to understand! Though I always end up using
#define
because 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
using
supports 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
int
tolong long
, so after continuous use of#define int long long
you 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 long
in 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_t
also worksprint
long long
manually until you're masterUse
using ll = long long
.It will replace
ll
withlong long
only in contexts wherell
is a type. It also makes a real type-level type alias.#define ll long long
will blindly replacell
token withlong long
tokens everywhere in your code even if it does not make sense. In particular, you won't be able to writell(10.5)
with#define
as you could with other types likeint(10.5)
.I always use "define int long long"^~^