-
Notifications
You must be signed in to change notification settings - Fork 0
/
eduround_152_div2_C.java
41 lines (38 loc) · 1.19 KB
/
eduround_152_div2_C.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.*;
public class eduround_152_div2_C {
static class Pair{
int x, y;
Pair(int x, int y){
this.x = x;
this.y = y;
}
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t --> 0){
List<Pair> list = new ArrayList<>();
int n = sc.nextInt();
int m = sc.nextInt();
String s = sc.next();
for(int i = 0;i<m;i++){
int l = sc.nextInt();
int r = sc.nextInt();
list.add(new Pair(l, r));
}
Set<String> set = new HashSet<>();
for(Pair p : list){
StringBuilder sb = new StringBuilder();
int l = p.x;
int r = p.y;
char c[] = s.substring(l-1, r).toCharArray();
Arrays.sort(c);
sb.append(s.substring(0,l-1));
sb.append(String.valueOf(c));
sb.append(s.substring(r));
set.add(sb.toString());
}
System.out.println(set.size());
}
}
}