C. String Reconstruction

题目连接:

http://codeforces.com/contest/828/problem/C

Description

Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one.

Ivan knows some information about the string s. Namely, he remembers, that string ti occurs in string s at least ki times or more, he also remembers exactly ki positions where the string ti occurs in string s: these positions are xi, 1, xi, 2, ..., xi, ki. He remembers n such strings ti.

You are to reconstruct lexicographically minimal string s such that it fits all the information Ivan remembers. Strings ti and string s consist of small English letters only.

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of strings Ivan remembers.

The next n lines contain information about the strings. The i-th of these lines contains non-empty string ti, then positive integer ki, which equal to the number of times the string ti occurs in string s, and then ki distinct positive integers xi, 1, xi, 2, ..., xi, ki in increasing order — positions, in which occurrences of the string ti in the string s start. It is guaranteed that the sum of lengths of strings ti doesn't exceed 106, 1 ≤ xi, j ≤ 106, 1 ≤ ki ≤ 106, and the sum of all ki doesn't exceed 106. The strings ti can coincide.

Output

Print lexicographically minimal string that fits all the information Ivan remembers.

Sample Input

3
a 4 1 3 5 7
ab 2 1 5
ca 1 4

Sample Output

abacaba

Hint

题意

给n个字符串,告诉你有n个位置的是这个字符串的开始,然后让你输出最后字符串的样子。

题解:

由于显然每个位置的字符是唯一的,换句话而言,就是每个位置我们都只用访问一次就够了,没必要重复的进行访问。

我们用并查集去维护这个就好了。

代码

#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
const int maxn = 2e6+7;
int fa[maxn];
int ans[maxn];
int fi(int x){return x==fa[x]?x:fa[x]=fi(fa[x]);
}
int n,mx=0;
string s;
int main(){scanf("%d",&n);for(int i=0;i<maxn;i++)fa[i]=i;int mx = 0;for(int i=0;i<n;i++){cin>>s;int k;scanf("%d",&k);for(int j=0;j<k;j++){int x;scanf("%d",&x);int st=x;int end=x+s.size();mx=max(mx,end);x=fi(x);while(x<end){ans[x]=s[x-st]-'a';int x2=fi(fi(x)+1);fa[fi(x)]=x2;x=x2;}}}for(int i=1;i<mx;i++)cout<<char(ans[i]+'a');cout<<endl;
}

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction 并查集相关推荐

  1. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution 树状数组

    链接: http://codeforces.com/contest/828/problem/E 题解: 给你一个字符串s  q次操作 op==1 改变s[pos]位置的字符  op==2 将字符串e复 ...

  2. D. Best Edge Weight(最小生成树 + 树链剖分)(Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals))

    D. Best Edge Weight 给定一个有nnn个点mmm条边的无向连通图,有mmm次询问,每次询问第iii条边的权值最大为多少,这张图的所有最小生成树的方案中,一定包含第iii条边. 先跑一 ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)

    昨晚的没来得及打,最近错过好几场CF了,这场应该不算太难 A. Unimodal Array time limit per test 1 second memory limit per test 25 ...

  4. Codeforces Round #700 (Div. 2)A~D2解题报告

    Codeforces Round #700 (Div. 2)A~D2解题报告 A Yet Another String Game 原题链接 http://codeforces.com/contest/ ...

  5. Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)切题报告(A-B题)

    这是我第二次参加CF比赛,也是第一次写博客,写得不好,望各位大佬海涵. A. Single Wildcard Pattern Matching 原题链接 这道题,这是难到让人无法直视,太水了. 题目大 ...

  6. Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))

    Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) 题号 题目 知识点 A Simply Strange Sor ...

  7. Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) A-F全题解

    Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) 文章目录 A. Simply Strange Sort B. ...

  8. C. Tyler and Strings(组合数学,树状数组维护前缀和)(Codeforces Round #775 (Div. 1, based on Moscow Open Olympiad i)

    对我来说比较困难的一题了,尝试着自己写了一下,调不出来遂放弃. Codeforces Round #775 (Div. 1, based on Moscow Open Olympiad in Info ...

  9. Codeforces Round #775 (Div. 2, based on Moscow Open Olympiad in Informatics)简训

    Codeforces Round #775 (Div. 2, based on Moscow Open Olympiad in Informatics)简训 导语 涉及的知识点 题目 A Game B ...

最新文章

  1. java待办功能 设计_高效人士的待办清单都用这些软件来做
  2. 20175305张天钰 《java程序设计》第四周课下测试总结
  3. Unity 官方网站
  4. SpringBoot 简单实现仿CAS单点登录系统
  5. win10系统文件拖拽卡顿_IT技巧分享16:如何让win10摆脱卡顿
  6. 用word写接口文档时的常规格式设置
  7. android 蓝牙 录音,Android 实现蓝牙录音
  8. HTML网页标签代码基本教学(1)基本标签学习
  9. 无限极分类在html怎么用,wxj.html
  10. JavaEE初阶---网络原理初识+网络编程套接字+网络原理之TCP_IP
  11. 关于2019年签证的总结:
  12. Linux双硬盘引导,Linux系统下双硬盘多系统引导深入探究
  13. 关于移动端IOS input弹起键盘时,引起高度问题
  14. 《微软云计算Windows Azure开发与部署权威指南》——6.8 AppFabric服务总线的多播服务开发...
  15. Neo4j入门之中国电影票房排行浅析
  16. 【打CF,学算法——四星级】CodeForces 86D Powerful array (莫队算法)
  17. 续谈大数据之足球盘口赔率水位分析思路及其实现利器
  18. python发邮件给多个人发送消息_【Python3】 发送邮件给多人
  19. c语言实现二分查找法
  20. 西安电子科技大学833真题_21西安电子科技大学计算机/软工考研经验分享

热门文章

  1. 6个你应该用用看的用于文本分类的最新开源预训练模型 忆臻
  2. 解密时刻:机器学习能力太强好吗?
  3. Facebook参与AI芯片设计大混战!
  4. 为你解读7大类深度CNN架构创新综述(附论文)
  5. 机器学习中的方法技术与应用场景
  6. 杭州往事之与L项目SME Cathy小聚
  7. CNN在中文文本分类的应用
  8. 福利丨一门面向所有人的人工智能公开课:MIT 6.S191,深度学习入门
  9. 深入理解padding_idx(nn.Embedding、nn.Embedding.from_pretrained)
  10. 这一年,宇宙“面目”愈发清晰