Master0fPuppets's blog

By Master0fPuppets, history, 6 weeks ago, In English

Problem:https://codeforces.com/contest/1234/problem/D

hi guys in this problem my solution got TLE so if anyone can give me just a hint about what I can edit to get Ac

MY Approach: first I created a vector of sets of size 26 the number of letters and then I did a loop on the whole string and stored the indexes of each letter and then in the queries if the number is one I go to the letter at this index and erase the index from the set and then add this index to the new letter and if the number is two I do a loop over the vector and use lower_bound to check if there is an index in the current letter that is >= l and <= r.Also, I think this solution is O(nlogn) (correct me if I am mistaken)

Code:https://ideone.com/jujNjB

Thank you in advance :)

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

The code is perfect, but there is one problem with the code, actually 2 problems the first problem is using fast input/output, which you already know but for some reason you commented it, i am assuming because you were debugging the code. and the second problem which actually made your code give you timelimit is that u used for(auto i : v), whats its actually doing is that it is copying the data to the variable i since you're not doing it by reference, so you can change it to for(auto &i : v) to access data by reference or use the traditional for(int i = 0; i < (int)v.size(); ++i) loop.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    thanx alot bro but i never thought that the not using reference would cause a TLE because it never happened to me before