Given a String S with length N (N <= 50000). Given Q (Q <= 2000) queries.
1) Sort the substring [L, R] lexicographically.
2) Find the value of substring [L, R]. A value of substring is the sum of all (S[i] — 'a' + 1) for L <= i <= R.
What data structure/algorithm can solve this problem?