String sorting - MarisaOJ: Marisa Online Judge

String sorting

Time limit: 3000 ms
Memory limit: 256 MB
Given a string S of length n consisting of lowercase letters, there are q queries of the form (l,r,k). If k is equal to 1, sort the substring S[l...r] in non-decreasing order; otherwise, if k is equal to 0, sort it in non-increasing order. ### Input - The first line contains two integers n,q. - The second line contains the string S. - The next q lines each contain three integers l,r,k. ### Output - Print the string S after performing the q queries. ### Constraints - 1≤n≤105, 1≤q≤5×104. ### Example Input: 74±yyrgz251450561241 Output: ±rygyz