#include <vector>
#include <cstdio>
#include <ctime>
#include <algorithm>
#include <iterator>
#include <utility>
using namespace std;
int main() {
int n = 100000,
dummy = -1,
n_remove_items = 10000;
vector<int> a(n, dummy);
vector<int> b(n, dummy);
vector<int> c;
clock_t start = clock(); {
random_shuffle(begin(a), end(a));
for (int i = 0; i < n_remove_items; i++) {
a.erase(begin(a));
}
} clock_t end = clock();
printf("a->size() = %d, %fsec.\n", a.size(), (double)(end - start) / CLOCKS_PER_SEC);
start = clock(); {
for (int i = 0; i < n_remove_items; i++) {
int index = rand() & b.size();
b[index] = 0;
}
copy_if(begin(b), std::end(b), back_inserter(c), // XXX : duplication name(end)
[&dummy](int x) {
return x == dummy;
});
b = move(c);
} end = clock();
printf("b->size() = %d, %fsec.\n", b.size(), (double)(end - start) / CLOCKS_PER_SEC);
return 0;
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGN0aW1lPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8aXRlcmF0b3I+CiNpbmNsdWRlIDx1dGlsaXR5PgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgaW50IG4gPSAxMDAwMDAsCgkJZHVtbXkgPSAtMSwKCQluX3JlbW92ZV9pdGVtcyA9IDEwMDAwOwoKCXZlY3RvcjxpbnQ+IGEobiwgZHVtbXkpOwoJdmVjdG9yPGludD4gYihuLCBkdW1teSk7Cgl2ZWN0b3I8aW50PiBjOwoKICAgIGNsb2NrX3Qgc3RhcnQgPSBjbG9jaygpOyB7CgkJcmFuZG9tX3NodWZmbGUoYmVnaW4oYSksIGVuZChhKSk7CgkJZm9yIChpbnQgaSA9IDA7IGkgPCBuX3JlbW92ZV9pdGVtczsgaSsrKSB7CgkJCWEuZXJhc2UoYmVnaW4oYSkpOwoJCX0KCX0gY2xvY2tfdCBlbmQgPSBjbG9jaygpOwogICAgcHJpbnRmKCJhLT5zaXplKC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