Editorial for ICPC NWERC 2011 C - Movie Collection


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
  • Note, since m,r=100000, you cannot update the stack in O(m) time
  • Therefore you need some smart data structure to store information
  • Binary indexed tree/Fenwick tree does the job in O(logm) time
  • At every step, take movie x and put it back on 1,2,3,

Note that this is also O(n2):

Copy
for (int j = 0; j < r; j++) {
  movie = sc.nextInt();
  index = movies.indexOf(movie);
  System.out.print("" + (m - index - 1) + " ");
  movies.removeElementAt(index);
  movies.add(movie);
}

Comments

There are no comments at the moment.