#include using namespace std; class Trie { public: Trie() { isComplete = false; for (int i = 0; i < 26; i++) { next[i] = NULL; } descendants = -1; r = 0; } Trie * next [26]; int r; bool isComplete; int descendants; bool contains(char i) { return next[i-'a']; } void insert(string s, int pos, int rate) { Trie * cur = this; Trie * nex = this; if (descendants == -1) { descendants = 1; } while (s.length() != pos) { nex = cur->next[s[pos]-'a']; if (!nex) { nex = new Trie(); nex->descendants = 0; cur->next[s[pos]-'a'] = nex ; } pos ++; nex->descendants ++; cur = nex; } cur->isComplete = true; cur->r += rate; return; } int traverse() { if (descendants == -1) { descendants = 0; for (int i = 0; i < 26; i++) { if (next[i]) descendants += next[i]->traverse(); } if (isComplete) descendants ++; } return descendants; } int find(string s, int pos) { Trie * cur = this; Trie * nex = this; while (s.length() != pos) { nex = cur->next[s[pos]-'a']; if (!nex) { return 0; } pos ++; cur = nex; } return cur->r; } }; int main(){ int n; cin >> n; vector genes(n); for(int genes_i = 0; genes_i < n; genes_i++){ cin >> genes[genes_i]; } vector health(n); for(int health_i = 0; health_i < n; health_i++){ cin >> health[health_i]; } int s; cin >> s; vector h(s); for(int a0 = 0; a0 < s; a0++){ int first; int last; string d; Trie head; cin >> first >> last >> d; int max = 0; for (int i = first; i <= last; i ++) { head.insert(genes[i], 0, health[i]); if (genes[i].length() > max) max = genes[i].length(); } // your code goes here int cur_pos; int total = 0; for(int i = 0; i < d.length(); i++) { for(int j = 1; j<=max; j++) { if ( i + j > d.length()) break; string to_f = d.substr(i, j); if (head.find(to_f, 0) > 0 ) cerr << to_f << " " << head.find(to_f, 0) << endl; total += head.find(to_f, 0); } } h[a0] = total; cerr << total << " "; } int min = h[0]; int max = h[0]; for(int i=0;imax) max=h[i]; } cout << min << " " << max; return 0; }