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 ...
随机推荐
- mybatis之接口绑定
接口绑定方案 mybatis中,提供了一套接口绑定方案,程序员可以提供一个接口,然后提供对应接口的一个mapper.xml文件.MyBatis会自动将接口和xml文件进行绑定.实际上就是mybatis ...
- 34.js----JS 开发者必须知道的十个 ES6 新特性
JS 开发者必须知道的十个 ES6 新特性 这是为忙碌的开发者准备的ES6中最棒的十个特性(无特定顺序): 默认参数 模版表达式 多行字符串 拆包表达式 改进的对象表达式 箭头函数 =&> ...
- gitlab4.0备份还原
一,备份 备份默认路径查看: gitlab/config/gitlab.yml 中的backup: 默认tmp/backups ====>这个是gitlab/tmp/backups/ 可不是系 ...
- C#中生成的随机数为什么不随机?
from:https://www.xcode.me/more/net-csharp-generate-random 随机数生成方法可以说是任何编程语言必备的功能,它的重要性不言而言,在C#中我们通常使 ...
- Mongo数据两表关联创建视图示例
表tblCard: {"cNo":"11","oRDate":ISODate("2017-08-01T00:00:00.000+0 ...
- Yii ActiveRecord生命周期
- Yii2返回以主键id为键名的数组
branch.php <?php namespace app\models; use Yii; /** * This is the model class for table "bra ...
- Python - 3. Input and Output
from:http://interactivepython.org/courselib/static/pythonds/Introduction/InputandOutput.html Input a ...
- Eclipse中tomcat更改部署路径 deply path
默认是部署在项目元数据文件夹.metadata文件夹下,需要更改到tomcat/webapps目录下 Eclipse中tomcat service设置 选择window ----show view-- ...
- 20165305 实验三 敏捷开发与XP实践
实验3-1 敏捷开发与XP实践 http://www.cnblogs.com/rocedu/p/4795776.html, Eclipse的内容替换成IDEA 参考 http://www.cnblog ...