String Sorting

You'll be given a string s=s1s2.....sns = s_1s_2.....s_ns=s1​s2​.....sn​ of length nnn consisting of lowercase english letters and qqq queries. In each query you'll be given two integers lll and rrr, you've to report the minimum number of operations you need to make in order to sort the substring slsl+1.....srs_ls_{l+1}.....s_rsl​sl+1​.....sr​. In one operation you can take two adjacent indices and swap the characters.


This is a companion discussion topic for the original entry at https://toph.co/p/string-sorting