1+ package c285 ;
2+
3+ import java .io .BufferedReader ;
4+ import java .io .IOException ;
5+ import java .io .InputStreamReader ;
6+ import java .util .ArrayList ;
7+ import java .util .List ;
8+ import java .util .StringTokenizer ;
9+
10+ public class Abc285_f {
11+ private static List <Fenwick > seg ;
12+
13+ public static void main (String [] args ) {
14+ FastReader scanner = new FastReader ();
15+ int N = scanner .nextInt ();
16+ String S = scanner .next ();
17+ char [] s = S .toCharArray ();
18+
19+ // 26 棵线段树
20+ seg = new ArrayList <>();
21+ for (int i = 0 ; i < 26 ; i ++) {
22+ seg .add (new Fenwick (N ));
23+ }
24+ int [] cnt = new int [26 ];
25+
26+ for (int i = 0 ; i < N ; i ++) {
27+ seg .get (s [i ] - 'a' ).add (i + 1 , 1 );
28+ cnt [s [i ] - 'a' ]++;
29+ }
30+
31+ int Q = scanner .nextInt ();
32+ while (Q -- > 0 ) {
33+ int op = scanner .nextInt ();
34+ if (op == 1 ) {
35+ int x = scanner .nextInt () - 1 ;
36+ char c = scanner .next ().charAt (0 );
37+
38+ seg .get (s [x ] - 'a' ).add (x + 1 , -1 );
39+ cnt [s [x ] - 'a' ]--;
40+ s [x ] = c ;
41+ seg .get (s [x ] - 'a' ).add (x + 1 , 1 );
42+ cnt [s [x ] - 'a' ]++;
43+ } else {
44+ int l = scanner .nextInt ();
45+ int r = scanner .nextInt ();
46+
47+ int [] ret = new int [26 ];
48+ for (int i = 0 ; i < 26 ; i ++) {
49+ ret [i ] = seg .get (i ).getSum (l , r );
50+ }
51+ int m = 0 , M = 26 ;
52+ while (ret [m ] == 0 ) m ++;
53+ while (ret [M - 1 ] == 0 ) M --;
54+ boolean flag = true ;
55+ for (int i = m + 1 ; i < M - 1 ; i ++) {
56+ flag &= (ret [i ] == cnt [i ]);
57+ }
58+ flag &= check (ret , l , r );
59+ System .out .println (flag ? "Yes" : "No" );
60+ }
61+ }
62+ }
63+
64+ private static boolean check (int [] ret , int l , int r ) {
65+ for (int i = 0 ; i < 26 ; i ++) {
66+ if (seg .get (i ).getSum (l , l + ret [i ] - 1 ) != ret [i ]) {
67+ return false ;
68+ }
69+ l += ret [i ];
70+ }
71+ return true ;
72+ }
73+
74+ private static class Fenwick {
75+ private final int N ;
76+ private final int [] tree ;
77+
78+ public Fenwick (int n ) {
79+ this .N = n ;
80+ this .tree = new int [N + 1 ];
81+ }
82+
83+ public int lowbit (int x ) {
84+ return x & (-x );
85+ }
86+
87+ // nums[x] add k
88+ public void add (int x , int k ) {
89+ while (x <= N ) {
90+ tree [x ] += k ;
91+ x += lowbit (x );
92+ }
93+ }
94+
95+ // nums [1,x] 的和
96+ public int getSum (int x ) {
97+ int ans = 0 ;
98+ while (x >= 1 ) {
99+ ans += tree [x ];
100+ x -= lowbit (x );
101+ }
102+ return ans ;
103+ }
104+
105+ // nums [l,r] 的和
106+ public int getSum (int l , int r ) {
107+ return getSum (r ) - getSum (l - 1 );
108+ }
109+ }
110+
111+ private static class FastReader {
112+ private final BufferedReader bufferedReader ;
113+ private StringTokenizer stringTokenizer ;
114+
115+ public FastReader () {
116+ bufferedReader = new BufferedReader (new InputStreamReader (System .in ));
117+ }
118+
119+ public String next () {
120+ while (stringTokenizer == null || !stringTokenizer .hasMoreElements ()) {
121+ try {
122+ stringTokenizer = new StringTokenizer (bufferedReader .readLine ());
123+ } catch (IOException e ) {
124+ e .printStackTrace ();
125+ }
126+ }
127+ return stringTokenizer .nextToken ();
128+ }
129+
130+ public int nextInt () {
131+ return Integer .parseInt (next ());
132+ }
133+
134+ public long nextLong () {
135+ return Long .parseLong (next ());
136+ }
137+
138+ public double nextDouble () {
139+ return Double .parseDouble (next ());
140+ }
141+
142+ public String nextLine () {
143+ String str = "" ;
144+ try {
145+ if (stringTokenizer .hasMoreTokens ()) {
146+ str = stringTokenizer .nextToken ("\n " );
147+ } else {
148+ str = bufferedReader .readLine ();
149+ }
150+ } catch (IOException e ) {
151+ e .printStackTrace ();
152+ }
153+ return str ;
154+ }
155+ }
156+ }
157+ /*
158+ F - Substring of Sorted String
159+ https://atcoder.jp/contests/abc285/tasks/abc285_f
160+
161+ 给定一个长度为N的字符串S,由小写英文字母组成,并进行Q次查询。按顺序处理查询。每个查询是以下两种类型之一:
162+ 1 x c: 将S的第x个字符替换为字符c。
163+ 2 l r: 设T为将S中的字符按升序排序得到的字符串。
164+ 如果由S的第l到第r个字符组成的字符串是T的子字符串,则打印Yes;否则,请打印No。
165+
166+ 树状数组 + Fast I/O
167+ 线段树会 TLE。。
168+ 不用 Fast I/O 也会 TLE
169+ */
0 commit comments