my AC used treap as data structure and binary search for the answer. In heap I have kept numbers of initial deleted rooms. After each query I was looking for this number. And if query is 'LOOK AT', I print it, else insert in treap. O(M * log^2K), where K is number of query 'D' P.S.: sorry for bad English.