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 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 stringsti.
You are to reconstruct lexicographically minimal string s such that it fits all the information Ivan remembers. Strings ti and string sconsist of small English letters only.
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 exceed106, 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.
Print lexicographically minimal string that fits all the information Ivan remembers.
3
a 4 1 3 5 7
ab 2 1 5
ca 1 4
abacaba
1
a 1 3
aaa
3
ab 1 1
aba 1 3
ab 2 3 5
ababab
我同学都用排序 + 并查集,然而我用链表 + 并查集思想。
因为数据合法不用判错,所以用链表维护还未确定的位置。每条信息,找第一个确定的位置时边找边压缩路径(并查集思想)。然后按题意弄一下即可。
另外吐槽一下这道题。。直接交代码在第十个点各种WA,RE(必须交G++14才能AC,而且跑得非常慢),然后cf上交文件AC。。(可能是你在逗我)
Code
/**
* Codeforces
* Problem#828C
* Accepted
* Time:296ms
* Memory:59888k
*/
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <stack>
#ifndef WIN32
#define Auto "%lld"
#else
#define Auto "%I64d"
#endif
using namespace std;
typedef bool boolean;
const signed int inf = (signed)((1u << ) - );
const signed long long llf = (signed long long)((1ull << ) - );
const double eps = 1e-;
const int binary_limit = ;
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
template<typename T>
inline boolean readInteger(T& u){
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-' && x != -);
if(x == -) {
ungetc(x, stdin);
return false;
}
if(x == '-'){
x = getchar();
aFlag = -;
}
for(u = x - ''; isdigit((x = getchar())); u = (u << ) + (u << ) + x - '');
ungetc(x, stdin);
u *= aFlag;
return true;
} int n;
int m = ;
string* strs;
vector<int> *pos;
boolean* exist;
char* res;
int* suf;
int* pre; inline void init() {
readInteger(n);
strs = new string[n];
pos = new vector<int>[n];
for(int i = ; i < n; i++) {
static int c, x, l;
cin >> strs[i];
l = strs[i].length();
readInteger(c);
for(int j = ; j < c; j++) {
readInteger(x);
pos[i].push_back(x);
smax(m, x + l - );
}
}
} inline void remove(int x) {
pre[suf[x]] = pre[x];
suf[pre[x]] = suf[x];
exist[x] = false;
} int find(int x, int endpos) {
if(exist[x] || x >= endpos) return x;
return suf[x] = find(suf[x], endpos);
} inline void solve() {
exist = new boolean[m + ];
suf = new int[m + ];
pre = new int[m + ];
res = new char[m + ];
memset(exist, true, sizeof(boolean) * (m + ));
suf[n + ] = m + , pre[] = ;
for(int i = ; i <= m; i++) suf[i] = i + ;
for(int i = ; i <= m + ; i++) pre[i] = i - ; for(int i = ; i < n; i++) {
int l = strs[i].length();
for(int j = ; j < (signed)pos[i].size(); j++) {
int p = pos[i][j], start = pos[i][j];
p = find(p, start + l);
while(p < pos[i][j] + l) {
res[p] = strs[i][p - start];
remove(p);
p = suf[p];
}
}
} for(int i = ; i <= m; i++)
if(exist[i])
res[i] = 'a';
res[m + ] = ; puts(res + );
} int main() {
init();
solve();
return ;
}
Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...
- 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 ...
- 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 ...
随机推荐
- 移动端的rem适配
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- DW表格的简单应用 之(个人简历模板)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- HTML-CSS线性渐变
实现背景的渐变可以通过为背景添加颜色渐变的图片,也可以使用浏览器的功能来为背景添加渐变的颜色 在IE6或IE7浏览器下可以使用一下示例的CSS语句,设置filter属性来实现颜色 filter:pro ...
- Service Fabric下删除实例并注销应用
Service Fabric下删除实例并注销应用: 以应用名称:Application1为例 1.打开PowerShell 2.连接集群: Connect-ServiceFabricCluster - ...
- Cassandra创建第一个用户
Cassandra配置文件cassandra.yaml 的配置项, 默认是 authenticator: AllowAllAuthenticator 现在想创建Cassandra的用户,但是如果保持以 ...
- HttpServletRequestWrapper
1). why 需要改变从 Servlet 容器 (可能是任何的 Servlet 容器)中传入的 HttpServletRequest 对象的某个行为,该怎么办? 一. 继承 HttpServletR ...
- sqoop从hive导入数据到mysql时出现主键冲突
今天在将一个hive数仓表导出到mysql数据库时出现进度条一直维持在95%一段时间后提示失败的情况,搞了好久才解决.使用的环境是HUE中的Oozie的workflow任何调用sqoop命令,该死的o ...
- flask模板应用-自定义错误页面
自定义错误页面 当程序返回错误响应时,会渲染一个默认的错误页面,我们可以注册错误处理函数来处理错误页面 错误处理函数和视图函数很相似,返回值将作为响应的主题,因此我们先要创建错误页面的模板文件.为了和 ...
- ref 参数与out参数
变量作为参数传给方法,同时希望在方法执行完成后对参数,反应到变量上面.就需要用到ref和out这两个参数. ref参数:在 传入前必须先初始化 out参数:不需要做预先的处理
- EasyUi通过OCUpload上传及POI上传 实现导入xls表格功能
Easyui上传文件案例 第一步:要想使用OCUpload首先前端需要导入js包 <script type="text/javascript" src=&qu ...