fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n; cin >> n;
  6. vector<string> store(n);
  7. for(int i = 0; i < n; i++){
  8. cin >> store[i];
  9. }
  10.  
  11.  
  12. vector<int> res(n,0);
  13. vector<vector<int>> map(200000+5, vector<int>(26+5,0));
  14. for(int i = n-1; i >= 0; i--){
  15. string s = store[i];
  16. int len = s.length();
  17. int cnt = 0;
  18. for(int j = 0; j < len; j++){
  19. char ch = s[j];
  20. int code = int(ch) - 97;
  21. cnt += map[j][code];
  22. map[j][code]++;
  23. }
  24. res[i] = cnt;
  25. }
  26.  
  27. for(int i = 0; i < n; i++)
  28. cout << res[i] << " ";
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.03s 36076KB
stdin
3
abc ade abc
stdout
4 1 0