void updateContainer(Cont<T, Alloc>& cont) { // flip a coin to determine using emplace_back() with 80% of likelihood, or pop_back() with 20% of likelihood. static std::bernoulli_distribution dist(.8); if (cont.empty() || dist(S1::s_gen)) { cont.emplace_back(); } else { cont.pop_back(); } // and with 20% likelihood mutating 1st and last elem's std::string field if (!cont.empty() && !dist(S1::s_gen)) { cont.front().m_str.append("- foo"); cont.back().m_str.append("- bar"); } }
void strategy1() { int numElems; cin >> numElems; Cont container; for (int ii = 0; ii < numElems; ii++) { container.push_back(0); cin >> container.back(); } for (int day = 0; ; day++) { list<ContIter> toDelete; ContIter iThis(container.begin()); ContIter iPrev(iThis); iThis++; while (iThis != container.end()) { if (*iThis > *iPrev) { toDelete.push_back(iThis); } iThis++; iPrev++; } if (toDelete.empty()) { cout << day << endl; break; } // cout << "toDelete "; // dump(toDelete); for (list<ContIter>::reverse_iterator iDel = toDelete.rbegin(); iDel != toDelete.rend(); iDel++) { container.erase(*iDel); } // dump(container); } }
T back() const { return elements.back().ub; }