library_checker/string/
number_of_substrings.rs1use competitive::prelude::*;
2#[doc(no_inline)]
3pub use competitive::string::SuffixArray;
4
5#[verify::library_checker("number_of_substrings")]
6pub fn number_of_substrings(reader: impl Read, mut writer: impl Write) {
7 let s = read_all_unchecked(reader);
8 let mut scanner = Scanner::new(&s);
9 scan!(scanner, s: Chars);
10 let mut ans = s.len() * (s.len() + 1) / 2;
11 let sa = SuffixArray::new(s);
12 let lcp = sa.longest_common_prefix_array();
13 for x in lcp {
14 ans -= x;
15 }
16 writeln!(writer, "{}", ans).ok();
17}