C. String Reconstruction
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

It is guaranteed that the input data is not self-contradictory, and thus at least one answer always exists.

Output

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

Examples
Input
3
a 4 1 3 5 7
ab 2 1 5
ca 1 4
Output
abacaba
Input
1
a 1 3
Output
aaa
Input
3
ab 1 1
aba 1 3
ab 2 3 5
Output
ababab
题意:n行 每行先给你一个字符串str 以及接下来的x位置 表示以某个位置开始的字符串部分为str 输出满足以上要求的字典序最小的字符串
题解:stl怼爆内存 这里用到了并查集 对于每个位置i的字符当确认之后 使得fa[i]=i+1 则不需要每次都遍历更新每个位置的字符 寻找其在范围内的fa即可
 #pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
using namespace std;
int fa[];
char ans[];
int find(int x)
{
if(fa[x]==x)
return x;
else
return fa[x]=find(fa[x]);
}
int n;
char a[];
int main()
{
scanf("%d",&n);
int exm;
int zong=;
for(int i=;i<=;i++){
ans[i]='a';
fa[i]=i;
}
for(int i=; i<=n; i++){
scanf("%s",a);
int len=strlen(a);
scanf("%d",&exm);
for(int j=;j<=exm;j++){
int ss;
scanf("%d",&ss);
int x=ss;
zong=max(zong,ss+len-);
while(x<=(ss+len-))
{
ans[x]=a[x-ss];
fa[x]=x+;x=find(x);
}
}
}
for(int i=;i<=zong;i++)
printf("%c",ans[i]);
printf("\n");
return ;
}

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C 并查集的更多相关文章

  1. Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)

    Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A.String Reconstruction B. High Load C ...

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

    E. DNA Evolution 题目连接: http://codeforces.com/contest/828/problem/E Description Everyone knows that D ...

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

    C. String Reconstruction 题目连接: http://codeforces.com/contest/828/problem/C Description Ivan had stri ...

  4. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 828E) - 分块

    Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A ...

  5. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集

    Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...

  6. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) D. High Load 构造

    D. High Load 题目连接: http://codeforces.com/contest/828/problem/D Description Arkady needs your help ag ...

  7. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) A,B,C

    A.题目链接:http://codeforces.com/contest/828/problem/A 解题思路: 直接暴力模拟 #include<bits/stdc++.h> using ...

  8. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心

    Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...

  9. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem A - B

    Pronlem A In a small restaurant there are a tables for one person and b tables for two persons. It i ...

随机推荐

  1. RedHat yum源配置

    RedHat yum源配置 原本以为Redhat7 和Centos7是完全一样的,可是安装完Redhat7以后,使用yum安装软件,提示红帽操作系统未注册.在网上搜索教程,最后成功解决,解决方式是将y ...

  2. python错误记录

    在主函数里调用其他函数时形参顺序要一致 错例如下:

  3. dp算法之硬币找零问题

    题目:硬币找零 题目介绍:现在有面值1.3.5元三种硬币无限个,问组成n元的硬币的最小数目? 分析:现在假设n=10,画出状态分布图: 硬币编号 硬币面值p 1 1 2 3 3 5 编号i/n总数j ...

  4. CentOS-6.x系列查看cpu核数

    使用CentOS7.x使用习惯了后用top命令,然后按1就可以查看相关的cpu核心数等相关信息 相关概念: 物理CPU:实际Server中插槽上的CPU个数. 物理cpu数量:可以数不重复的 phys ...

  5. 01慕课网《进击Node.js基础(一)》Node.js安装,创建例子

    版本:偶数位为稳定版本,基数为非稳定版本 - 0.6.x - 0.7.x    - 0.8.x -0.9.x    -0.10.x  -0.11.x 概念:Node.js采用谷歌浏览器的V8引擎,用C ...

  6. Java中switch可以接收的数据类型

    Java支持的数据类型有五种 他们分别是: byte.char.short.int.enum: 以上是JDK1.6以前的版本. JDK1.7时,又增加了String, public class Tes ...

  7. Programming Protocol-Independent Packet Processors

    引言 OpenFlow协议固定的包头域数目,使得南向协议过于死板. P4可以实现自定义包头,增加灵活性. P4是OpenFlow未来发展的方向. We propose P4 as a strawman ...

  8. 软工1816 · BETA 版冲刺前准备

    任务博客 组长博客 总的来讲Alpha阶段我们计划中的工作是如期完成的.不过由于这样那样的原因,前后端各个任务完成度不算非常高,距离完成一个真正好用.完美的软件还有所差距. 过去存在的问题 测试工作未 ...

  9. 通过一台服务器ssh多台主机远程修改网卡ip

    在多台服务器环境下,更改所有的ip地址,网关,一台一台的登录修改显得复杂繁琐.   知识点: 参考#https://www.cnblogs.com/youngerger/p/9104144.html ...

  10. arp请求与回复

    实验环境:wifi 1,手机192.168.1.103 2,电脑192.168.1.106 先删除电脑arp表数据 ping request: reply: