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.
Submitting an official solution before solving the problem yourself is a bannable offence.
- Note, since , you cannot update the stack in time
- Therefore you need some smart data structure to store information
- Binary indexed tree/Fenwick tree does the job in time
- At every step, take movie and put it back on
Note that this is also :
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