#include <vector>
#include <map>
#include <iostream>
std::vector<std::size_t> findDuplicateIndices(std::vector<int> const & v)
{
std::vector<std::size_t> indices;
std::map<int, std::pair<int, std::size_t>> counts;
for (std::size_t i = 0 ; i < v.size() ; ++i)
{
std::size_t amount = ++counts[v[i]].first;
/**/ if (amount == 1)
{
counts[v[i]].second = i;
continue;
}
else if (amount == 2)
indices.push_back(counts[v[i]].second);
indices.push_back(i);
}
return indices;
}
int main()
{
auto duplicateIndices = findDuplicateIndices({1,1,2,3,4,1,3});
for (auto i : duplicateIndices) std::cout << i << ',';
std::cout << std::endl;
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RkOjp2ZWN0b3I8c3RkOjpzaXplX3Q+IGZpbmREdXBsaWNhdGVJbmRpY2VzKHN0ZDo6dmVjdG9yPGludD4gY29uc3QgJiB2KQp7CglzdGQ6OnZlY3RvcjxzdGQ6OnNpemVfdD4gaW5kaWNlczsKCXN0ZDo6bWFwPGludCwgc3RkOjpwYWlyPGludCwgc3RkOjpzaXplX3Q+PiBjb3VudHM7CgoJZm9yIChzdGQ6OnNpemVfdCBpID0gMCA7IGkgPCB2LnNpemUoKSA7ICsraSkKCXsKCQlzdGQ6OnNpemVfdCBhbW91bnQgPSArK2NvdW50c1t2W2ldXS5maXJzdDsKCQkvKiovIGlmIChhbW91bnQgPT0gMSkKCQl7CgkJCWNvdW50c1t2W2ldXS5zZWNvbmQgPSBpOwoJCQljb250aW51ZTsKCQl9CgkJZWxzZSBpZiAoYW1vdW50ID09IDIpCgkJCWluZGljZXMucHVzaF9iYWNrKGNvdW50c1t2W2ldXS5zZWNvbmQpOwoKCQlpbmRpY2VzLnB1c2hfYmFjayhpKTsKCX0KCXJldHVybiBpbmRpY2VzOwp9CgppbnQgbWFpbigpCnsKCWF1dG8gZHVwbGljYXRlSW5kaWNlcyA9IGZpbmREdXBsaWNhdGVJbmRpY2VzKHsxLDEsMiwzLDQsMSwzfSk7Cglmb3IgKGF1dG8gaSA6IGR1cGxpY2F0ZUluZGljZXMpIHN0ZDo6Y291dCA8PCBpIDw8ICcsJzsKCXN0ZDo6Y291dCA8PCBzdGQ6OmVuZGw7Cn0=