CF827A String Reconstruction
今日胡策题
一个披着字符串外衣的并查集qwq
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 const int sz = 1000000; 6 int n, m, maxx = 0, len = 0, pos = 0; 7 int f[sz+10]; 8 string ans=""; 9 void init() { 10 for(int i = 0; i < sz; i++) { 11 f[i] = i; 12 ans += "a"; 13 } 14 } 15 int find(int x) { 16 if(x != f[x]) f[x] = find(f[x]); 17 return f[x]; 18 } 19 void print() { 20 for(int i = 0; i < maxx; i++) 21 cout<<ans[i]; 22 } 23 int main() { 24 // freopen("tsf.in", "r", stdin); 25 // freopen("tsf.ans", "w", stdout); 26 scanf("%d", &n); 27 init(); 28 for(int i = 1; i <= n; i++) { 29 string s; 30 cin>>s; 31 scanf("%d", &m); 32 int len = s.size(); 33 for(int j = 1; j <= m; j++) { 34 scanf("%d", &pos); 35 pos -= 1; 36 int mid = pos + len; 37 if(mid > maxx) maxx = mid; 38 for(int k = pos; k < mid; ) { 39 int r1 = find(k); 40 if(r1 > mid - 1) break; 41 ans[r1] = s[r1 - pos]; 42 f[r1] = r1 + 1; 43 k = f[r1]; 44 } 45 } 46 } 47 print(); 48 return 0; 49 }