File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -10,11 +10,13 @@ fn main() {
1010 q: usize
1111 }
1212
13+ let num_queries_find_substr = q. min ( 100 ) ;
14+
1315 let mut s = s. chars ( ) . map ( |x| x as usize ) . collect :: < Vec < usize > > ( ) ;
1416
1517 let mut length = vec ! [ s. len( ) ] ;
1618
17- for _ in 0 ..q {
19+ for _ in 0 ..num_queries_find_substr {
1820 input ! {
1921 t: String ,
2022 }
@@ -26,11 +28,25 @@ fn main() {
2628 let suf_ary = SufAry :: new ( & s, 255 ) ;
2729 let rmq = RMQ :: new ( & suf_ary. sa , std:: cmp:: min) ;
2830
29- for i in 0 ..q {
31+ for i in 0 ..num_queries_find_substr {
3032 let idx = rmq. query ( suf_ary. find_substr ( length[ i] ..length[ i + 1 ] ) ) ;
3133 println ! (
3234 "{}" ,
3335 ( idx + length[ i + 1 ] - length[ i] <= length[ 0 ] ) as usize
3436 ) ;
3537 }
38+
39+ for _ in num_queries_find_substr..q {
40+ input ! {
41+ t: String ,
42+ }
43+ let t = t. chars ( ) . map ( |x| x as usize ) . collect :: < Vec < usize > > ( ) ;
44+ let match_range = suf_ary. find_str ( & t) ;
45+ let idx = if match_range. is_empty ( ) {
46+ * length. last ( ) . unwrap ( )
47+ } else {
48+ rmq. query ( match_range)
49+ } ;
50+ println ! ( "{}" , ( idx + t. len( ) <= length[ 0 ] ) as usize ) ;
51+ }
3652}
You can’t perform that action at this time.
0 commit comments