I want to reuse it . How am I supposed to do it?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
I want to reuse it . How am I supposed to do it?
Name |
---|
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.