记录每个字母出现的位置,查找的时候用二分优化,时间复杂度nlogn #include<iostream> #include<vector> using namespace std; string str; char t[1000005]; int n; vector<int> space[150]; int binary_search(const vector<int> &arr, int k) { int l = 0, r = arr.size() - 1, middle; if(r == -1) return -1; while(l ...