Language: C++

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

int n;
int q;

#define MAX 400002

char buf[MAX];

vector<string> v;

struct st{
	st *linkk[27];
	int cnt;
	int belong;
	int att;
	st(){
		for (int i = 0; i < 27; i++){
			linkk[i] = NULL;
		}
		cnt = 0;
	}
};

st linkk[MAX * 40];
int ord = 0;
st *neww(){
	ord++;
	return &linkk[ord - 1];
}
st *root = neww();
vector<st*> lis;

void ins(string &a){
	st *b = root;
	for (int i = 0; i < a.size(); i++){
		if (b->linkk[a[i]-'a'] == NULL){
			b->linkk[a[i] - 'a'] = neww();
		}
		b = b->linkk[a[i] - 'a'];
	}
	lis.push_back(b);
}

inline void dfs(st *b){
	b->cnt = 1;
	for (int i = 0; i < 26; i++){
		if (b->linkk[i] != NULL){
			dfs(b->linkk[i]);
			b->cnt += b->linkk[i]->cnt;
		}
	}
}
struct HL{
	vector<int> bit[26];
	st * pr;
	void resize(int b){
		for (int i = 0; i < 26; i++){
			bit[i].assign(b+2, 0);
		}
	}
	HL(st *pr_){
		pr = pr_;
	}
};
vector<HL> hl;
inline void dfs2(st *b,int belong,int att){
	b->att = att;
	b->belong = belong;
	if (b->cnt == 1){
		hl[belong].resize(att);
		return;
	}
	int id = -1;
	int mx = -1;
	for (int i = 0; i < 26; i++){
		if (b->linkk[i] != NULL){
			if (mx < b->linkk[i]->cnt){
				mx = b->linkk[i]->cnt;
				id = i;
			}
		}
	}
	for (int i = 0; i < 26; i++){
		if (b->linkk[i] != NULL){
			if (i == id){
				dfs2(b->linkk[i], belong, att + 1);
			}
			else{
				hl.push_back(HL(b));
				dfs2(b->linkk[i], hl.size() - 1, 0);
			}
		}
	}
}

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		scanf("%s", buf);
		v.push_back(buf);
		ins(v.back());
	}
	dfs(root);
	hl.push_back(HL(NULL));
	dfs2(root, 0, 0);

	int q;
	scanf("%d", &q);
	while (q--){
		int id;
		scanf("%d", &id);
		id--;
		scanf("%s", buf);
		
	}
	return 0;
}

Compiler output:
/tmp/cczro9GT.o: in function `neww()':
a.cc:(.text+0x6): relocation truncated to fit: R_X86_64_PC32 against symbol `ord' defined in .bss section in /tmp/cczro9GT.o
a.cc:(.text+0xf): relocation truncated to fit: R_X86_64_PC32 against symbol `ord' defined in .bss section in /tmp/cczro9GT.o
a.cc:(.text+0x15): relocation truncated to fit: R_X86_64_PC32 against symbol `ord' defined in .bss section in /tmp/cczro9GT.o
/tmp/cczro9GT.o: in function `ins(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
a.cc:(.text+0x43): relocation truncated to fit: R_X86_64_PC32 against symbol `root' defined in .bss section in /tmp/cczro9GT.o
a.cc:(.text+0x113): relocation truncated to fit: R_X86_64_PC32 against symbol `lis' defined in .bss section in /tmp/cczro9GT.o
/tmp/cczro9GT.o: in function `main':
a.cc:(.text+0x20a): relocation truncated to fit: R_X86_64_PC32 against symbol `root' defined in .bss section in /tmp/cczro9GT.o
a.cc:(.text+0x237): relocation truncated to fit: R_X86_64_PC32 against symbol `hl' defined in .bss section in /tmp/cczro9GT.o
a.cc:(.text+0x255): relocation truncated to fit: R_X86_64_PC32 against symbol `root' defined in .bss section in /tmp/cczro9GT.o
/tmp/cczro9GT.o: in function `__static_initialization_and_destruction_0()':
a.cc:(.text+0x3b4): relocation truncated to fit: R_X86_64_PC32 against symbol `root' defined in .bss section in /tmp/cczro9GT.o
a.cc:(.text+0x3bb): relocation truncated to fit: R_X86_64_PC32 against symbol `lis' defined in .bss section in /tmp/cczro9GT.o
a.cc:(.text+0x3d4): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status