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 ...
随机推荐
- sqli-labs(六)
第十一关: 这关是一个登陆口,也是一个sql注入的漏洞,也就是常说的万能密码. 在输入框账号密码种分别输入 1' 和1' 页面会报错. 后台使用的单引符号进行的拼接.账号输入1' or '1'=' ...
- JDK源码调试常见错误。
1.删除不需要的代码,即swing相关的代码 2.执行命令时要将前提环境进入文件夹如下: 起初没有完全执行第一条,因为网上说可以根据需要选择相关的代码,于是就没有删除,以后第一次模仿网上的例子的时候要 ...
- python--教你做个最简单的tcp通信。。
TCP协议:建立在IP协议之上的,TCP协议,传输控制协议(英语:Transmission Control Protocol,缩写为 TCP)是一种面向连接的.可靠的.基于字节流的传输层通信协议,由I ...
- Git-分支的建立与合并
举一个实际工作中可能会遇到的分支建立与合并的例子: 开发某个网站. 为实现某个新的需求,创建一个分支. 在这个分支上开展工作. 假设此时,你突然接到一个电话说有个很严重的问题需要紧急修补,那么可以按照 ...
- 11.match
(我对部分段落进行翻译) A match statement is used to branch execution of a program. It’s the equivalent of the ...
- jQuery属性--attr(name|properties|key,value|fn)和removeAttr(name)
attr(name|properties|key,value|fn) 概述 设置或返回被选元素的属性值 参数 key,function(index, attr) 1:属性名称:2:返回 ...
- 基于TCP/IP协议的socket通讯client
package com.ra.car.utils; import java.io.BufferedReader; import java.io.IOException; import java.io. ...
- Linux基础命令---文本编辑ex
ex ex会启动vim编辑器,它的执行效果和vim –E相同.从ex模式回到普通模式,可以在vim中输入:vim. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.op ...
- .NET 常用ORM之Nbear
NBear是一个基于.Net 2.0.C#2.0开放全部源代码的的软件开发框架类库.NBear的设计目标是尽最大努力减少开发人员的工作量,最大程度提升开发效率,同时兼顾性能及可伸缩性. 一.新建项目并 ...
- SSM的理解
SSM(Spring+SpringMVC+MyBatis)框架集由Spring.SpringMVC.MyBatis三个开源框架整合而成,常作为数据源较简单的web项目的框架.其中spring是一个轻量 ...