Language: C++

#include <bits/stdc++.h>
using namespace std;

const int N = 100010;

class Node {
public:
	bool is_terminal;
	int cnt;
	Node *son[26];

	Node() {
		is_terminal = false;
		cnt = 0;
		for (int i = 0; i < 26; i++)
			son[i] = nullptr;
	}
};

class Trie {
public:
	Node *root;

	Trie() {
		root = new Node();
	}

	void insert(string &s) {
		Node *cur = root;
		for (char c: s) {
			int num = c - 'a';
			if (!cur->son[num]) 
				cur->son[num] = new Node();
			cur = cur->son[num];
			cur->cnt++;
		}
		cur->is_terminal = true;
	}
};


int n, q, data[N][26][26], pref[N];
string s[N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	Trie *trie = new Trie();
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
		trie->insert(s[i]);
	}
	for (int i = 1; i <= n; i++) {
		Node *cur = trie->root;
		for (char c: s[i]) {
			int num = c - 'a';
			for (int j = 0; j < 26; j++) 
				if (j != num && cur->son[j]) 
					data[i][num][j] += cur->son[j]->cnt;
			cur = cur->son[num];
			if (cur->is_terminal) pref[i]++;
		}
	}
	cin >> q;
	while (q--) {
		int k, ans = 0;
		string alpha;
		cin >> k >> alpha;
		vector<int> order(26);
		for (int i = 0; i < 26; i++)
			order[alpha[i] - 'a'] = i;
		for (int i = 0; i < 26; i++)
			for (int j = 0; j < 26; j++) 
				if (order[i] > order[j])
					ans += data[k][i][j];
		cout << ans + pref[k] << '\n';
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:59:41: error: reference to 'data' is ambiguous
   59 |                                         data[i][num][j] += cur->son[j]->cnt;
      |                                         ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:42:11: note:                 'int data [100010][26][26]'
   42 | int n, q, data[N][26][26], pref[N];
      |           ^~~~
a.cc:75:48: error: reference to 'data' is ambiguous
   75 |                                         ans += data[k][i][j];
      |                                                ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:42:11: note:                 'int data [100010][26][26]'
   42 | int n, q, data[N][26][26], pref[N];
      |           ^~~~