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 ...
随机推荐
- SwingBench 字符模式压测最佳实践
之前写过<使用SwingBench 对Oracle RAC DB性能 压力测试>,使用的是最基础直观的图形模式,已经可以满足大多数需求. 但是在有些场景下,图形模式可能本身消耗资源过大,尤 ...
- JavaScript原型继承的实例
// 创建构造函数实例(获取DOM节点) <div id="app">测试字符</div>
- JavaScript--Document对象方法createElement()和createTextNode()
createElement() 方法通过指定名称创建一个元素 createTextNode() 可创建文本节点 <!DOCTYPE html> <html> <head& ...
- loadrunner 更新中......
一.安装及参考说明 1.51 testing 链接:http://www.51testing.com/zhuanti/LoadRunner.html 2.官网链接:http://learnloadru ...
- maven工程的common模块jar上传至仓库并被其它模块依赖
.parent pom和common pom 都需要添加 <distributionManagement> <repository> <id>nexus</i ...
- [openjudge-动态规划]怪盗基德的滑翔翼
题目描述 描述 怪盗基德是一个充满传奇色彩的怪盗,专门以珠宝为目标的超级盗窃犯.而他最为突出的地方,就是他每次都能逃脱中村警部的重重围堵,而这也很大程度上是多亏了他随身携带的便于操作的滑翔翼. 有一天 ...
- timestamp与timedelta,管理信息系统概念与基础
1.将字符串‘2017年10月9日星期一9时10分0秒 UTC+8:00’转换为timestamp. 2.100天前是几号? 今年还有多少天? #timestamp与timedelta from ...
- 【Redis学习之七】Redis持久化
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 redis-2.8.18 什么是持久化? 将数据从掉电易失的 ...
- Lua语言总结
[1]要退出交互模式和解释器,只需输入“os.exit()” [2]在交互模式执行程序块可以使用函数dofile,这个函数就可以立即执行一个文件.应用示例:dofile("f:/myLua/ ...
- flask 表单
表单 在Web程序中,表单时和用户交互最常见的方式之一.用户注册.登录.撰写文章.编辑设置,无一不用到表单.不过,表单的处理不简单.要创建表单,验证用户输入的内容,向用户显示错误提示,还要获取并保存数 ...