I want to reuse it . How am I supposed to do it?
№ | Пользователь | Рейтинг |
---|---|---|
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 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 150 |
I want to reuse it . How am I supposed to do it?
Название |
---|
I have just tested this, but it said that pair has no member named clear, so where is the problem please.
for vector...!!!
for (int i = 0; i < 200; i++) { v[i].clear(); }
Or
fill(v, v + 200, {0, {0, 0}});
Which one is better ??? i usually use the first one.....
How can you usually use the first one, if it doesn't even work? xd
in order to avoid running a loop, you can make it like this :-
vector< pair<ll , pair<ll,ll> > > p; and then resize as u want it.
Yes, but
p.clear()
will not assign0's
to the vector's indexes, it will just make the pointer of this vector points to the first index again so if you usepush_back
method for example, it will push in the first index.But if you call
p[x]
just after clearing the vector, it will give you what index 'x' had before clearing.yes you just have to be careful with that . .
aboAdnan He mentioned resizing the vector, which default initializes the vector. It is going to work perfectly fine what the OP asked for.
I thought the question is about resetting the array (assigning zero to each element of it), but
resize
doesn't do that, does it?Yeah. If you provide a value with resize, they will fill the value with it. Otherwise, they will be filled with default value, zero in this case.
He mentioned you want to eliminate the loop with that. But, this wont reduce the runtime.
Defining clear would be better. There is nothing like clearing an array. Maybe, You meant zero initialize. Some people uses memset which is not going to be portable. I prefer using fill function.