Five problems where a set does the remembering: how many different numbers or words there are, whether something is on a list, and which letters appear in a part of a string that keeps changing.
- "How many different?" — insert everything into a set and print
s.size(). It works for words too:set<string>. - For questions about a list, read the whole list into a set first, then answer
each question with
count. - The butterfly numbers go up to 2·10⁹. That still fits an
int(the limit is about 2.1·10⁹), butlong longcosts nothing and leaves no doubt. - Up to 3·10⁵ words and 3·10⁵ questions: use the fast-IO lines and
"\n". - For the letters, keep one set of positions per letter. A change moves one
position from the old letter's set to the new one's; a question checks all 26
letters with
lower_bound.