【CodeForces - 827A】String Reconstruction(并查集合并区间,思维)

题干:

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

题目大意:

有一个字符串,最长1e6,现在给你若干个它的子字符串,每个子字符串长度不超过1e6,最多给你1e5个子字符串,告诉你第i个子字符串出现了ki次,并告诉你它每次出现的第一个字符的位置。所有子字符串的长度之和不超过1e6,出现的次数总和也不超过1e6。然后问你最短的满足要求的字符串中字典序最小的那个是什么。

输入是这样的:

第一行一个数n,代表有n个子字符串。

接下来n行,第i行 先是一个子字符串,然后一个数ki,然后ki个数,每个数代表第i个子字符串的第一个数分别出现的位置。

输入合法。

解题报告:

  因为构造出的字符串最多1e6且输入合法,所以直接在每个位置填充就可以了,当然暴力填充的话可能会有很多重复填充,所以用并查集维护一下第i个字符后面第一个空位。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 5e6 + 5;
int mx,f[MAX];
char s[MAX],ans[MAX];
int getf(int v) {return f[v] == v ? v : f[v] = getf(f[v]);
}
int main()
{int n;cin>>n;for(int i = 1; i<MAX; i++) f[i] = i,ans[i] = 'a';for(int num,x,len,i = 1; i<=n; i++) {scanf("%s%d",s+1,&num);len=strlen(s+1);for(int j = 1; j<=num; j++) {scanf("%d",&x);mx = max(mx,x+len-1);for(int k = x; k<=x+len-1; k=getf(k+1)) {ans[k] = s[k-x+1];f[k] = k+1;//=f[k+1]或者getf(k+1)其实都可以,只要记得在使用的时候getf一下就好,这题是巧了k就是根节点了,所以可以这样操作。也就是并查集使用的时候要保证,操作的节点必须是根节点,但是不一定接在人家的根节点上。}}} for(int i = 1; i<=mx; i++) printf("%c",ans[i]);return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/439606.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

详解自动驾驶仿真框架OpenCDA: An Open Cooperative Driving Automation Framework Integrated with Co-Simulation

本文介绍一款同时支持协同驾驶开发与测试、自动驾驶全栈开发 和 CARLA-SUMO联合仿真的开源框架 OpenCDA&#xff0c;论文已收录于 ITSC 2021。主要feature有&#xff1a; 支持CARLA-SUMO联合仿真&#xff0c;CARLA端主管环境渲染、传感器模拟、车辆动力&#xff0c;Sumo端主管…

JavaMonitor 监视器

为什么wait(), notify()和notifyAll()必须在同步方法或者同步块中被调用&#xff1f; 当一个线程需要调用对象的wait()方法的时候&#xff0c;这个线程必须拥有该对象的锁&#xff0c;接着它就会释放这个对象锁并进入等待状态直到其他线程调用这个对象上的notify()方法。同样的…

KITTI自动驾驶数据集可视化教程

本文介绍关于自动驾驶数据集KITTI的基本操作&#xff0c;包括Camera和LiDAR可视化教程&#xff0c;源码已上传&#xff1a;https://download.csdn.net/download/cg129054036/20907604 1. 数据准备 将 KITTI 数据 (calib, image_2, label_2, velodyne) 添加到 dataset/KITTI/ob…

【CodeForces - 746E】Numbers Exchange(贪心构造)

题干&#xff1a; Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers w…

java synchronized 关键字(1)对象监视器为Object

在java多线程中 synchronized 是非常重要的&#xff0c;也是经常用到的 对于synchronized关键字要注意两点 synchronized对象监视器为Object的时候 synchronized对象监视器为Class的时候 对象监视器为Object 也就是synchronized锁定的是对象 例如下面代码 public class A …

重读经典《Quaternion kinematics for the error-state Kalman filter》

本文将介绍一篇关于 四元数运动学的误差卡尔曼滤波 经典论文。本文结构如下&#xff1a; 第1章四元数定义和性质介绍&#xff0c;包括&#xff1a;加法、减法、乘法&#xff08;矩阵表示&#xff09;、模、幂数、指数运算等。第2章旋转群定义和性质介绍&#xff0c;包括&#…

【CodeForces - 789C】Functions again(最大子段和变形,dp,思维)

题干&#xff1a; Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are wo…

一步步编写操作系统 55 CPL和DPL入门2

接上节。 图中第132行的jmp指令&#xff0c;段选择子为SELECTOR_CODE&#xff0c;其RPL的值为RPL0&#xff0c;RPL0定义在include/boot.inc中&#xff0c;其值为0。选择子的索引部分值为1&#xff0c;表示对应GDT中第1个段描述符&#xff0c;该描述符的DPL为0&#xff0c;&…

详解停车位检测算法 Vision-Based Parking-Slot Detection: A DCNN-Based Approach and a Large-Scale Benchmark

本文介绍一篇基于深度学习的停车位检测论文&#xff1a;DeepPS&#xff0c;作者同时公开了数据集ps2.0&#xff0c;工作很扎实&#xff0c;对于入门停车位检测很有帮助&#xff0c;论文发表在 IEEE T-IP 2018。 项目链接为&#xff1a;https://cslinzhang.github.io/deepps/ 0…

【CodeForces - 789D】Weird journey(思维,图的性质,tricks,有坑)

题干&#xff1a; Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia. It is widely known that Uzhlyandia has n cities connected with m bidirectional roads. Also, there are no two roads…

Monitor(管程)是什么意思?Java中Monitor(管程)的介绍

本篇文章给大家带来的内容是关于Monitor&#xff08;管程&#xff09;是什么意思&#xff1f;Java中Monitor&#xff08;管程&#xff09;的介绍&#xff0c;有一定的参考价值&#xff0c;有需要的朋友可以参考一下&#xff0c;希望对你有所帮助。 monitor的概念 管程&#x…

详解经典GPS辅助惯性导航论文 A GPS-aided Inertial Navigation System in Direct Configuration

本文介绍一篇 IMU 和 GPS 融合的惯性导航论文&#xff0c;重点是理解本文提出的&#xff1a;Dynamical constraints update、Roll and pitch updates 和 Position and heading updates。 论文链接为&#xff1a;https://www.sciencedirect.com/science/article/pii/S166564231…

【POJ - 2151】Check the difficulty of problems(概率dp)

​​​​题干&#xff1a; Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually expect the contest result satisfy the following two terms: 1. All of the teams solve at least one problem. 2.…

jsp之九大内置对象与四大域对象

一,什么是内置对象? 在jsp开发中会频繁使用到一些对象,如ServletContext HttpSession PageContext等.如果每次我们在jsp页面中需要使用这些对象都要自己亲自动手创建就会特别的繁琐.SUN公司因此在设计jsp时,在jsp页面加载完毕之后自动帮开发者创建好了这些对象,开发者只需要使…

详解停车位检测论文:Attentional Graph Neural Network for Parking-slot Detection

本文介绍一篇注意力图神经网络用于停车位检测论文&#xff0c;论文已收录于 RA-L2021。在之前的基于卷积神经网络的停车位检测方法中&#xff0c;很少考虑停车位标记点之间的关联信息&#xff0c;从而导致需要复杂的后处理。在本文中&#xff0c;作者将环视图中的标记点看作图结…

【Codeforces - 769D】k-Interesting Pairs Of Integers(暴力,统计,思维,数学,异或)

题干&#xff1a; Vasya has the sequence consisting of n integers. Vasya consider the pair of integers x and y k-interesting, if their binary representation differs from each other exactly in k bits. For example, if k  2, the pair of integers x  5 and …

JSP的三六九四七(三大指令、六大标签、九大内置对象、四大作用域、七个动作指令)

JSP的基本构成&#xff1a;HTML文件Java片断JSP标签 三大指令&#xff1a;page指令、include指令、taglib指令。 page指令: 1.language属性&#xff1a;设置当前页面中编写JSP脚本使用的语言&#xff0c;默认值为java。 <%page language"java"%> 2.content…

详解3D物体检测模型 SPG: Unsupervised Domain Adaptation for 3D Object Detection via Semantic Point Generation

本文对基于激光雷达的无监督域自适应3D物体检测进行了研究&#xff0c;论文已收录于 ICCV2021。 在Waymo Domain Adaptation dataset上&#xff0c;作者发现点云质量的下降是3D物件检测器性能下降的主要原因。因此论文提出了Semantic Point Generation (SPG)方法&#xff0c;首…

【CodeForces - 722D】Generating Sets(二分,贪心)

题干&#xff1a; You are given a set Y of n distinct positive integers y1, y2, ..., yn. Set X of n distinct positive integers x1, x2, ..., xn is said to generate set Y if one can transform X to Y by applying some number of the following two operati…

Waymo研发经理:《自动驾驶感知前沿技术介绍》

Waymo研发经理|自动驾驶感知前沿技术介绍这是Waymo研发经理&#xff08;VoxelNet作者&#xff09;的一个最新分享报告&#xff1a;《自动驾驶感知前沿技术介绍》。在这份报告里&#xff0c;介绍了Waymo在自动驾驶感知中五个研究方向的最新成果。 1. Overview of the autonomous…