CodeForces Round #423 Div2C&Div1A(827A) Solution
来源:互联网 发布:阿里云ecs搭建windows 编辑:程序博客网 时间:2024/06/09 13:56
题意:给出若干子串(length<=1e6),每个子串给出若干index(小于1e6个),表示这个子串在原串的这些地方出现了,求字典序最小的原串,保证一定存在。
题解:保证一定存在的意思是,用char去填空,不会出现冲突的情况。只需要把每个串的每个index都填一遍,然后空位换成‘a’输出就可以了。现在的问题是,串太多,index太多,要降低复杂度。因为不存在冲突的情况,因此填上字符的位置,不需要再做检查和重复填写,因此用并查集维护连续的finished的线段。(这不就是0$大腿给我讲的那个并查集的题吗。。。嗯。确实想到了。但是并查集写起来还是要注意一下,要不然路径压缩失效还是会TLE。注意合并的时候是father[i]=find(i+1);而不是father[i]=father[i+1]这样没有路径压缩,会gg掉。
Code:
#include<bits/stdc++.h>using namespace std;#define MAX 1000006int father[MAX*3];char ans[MAX*3];char temp [MAX*3];int n;int maxlength = -1;int find(int x){ return father[x]==x?x:father[x]=find(father[x]);}int main(){ for (int i=0;i<MAX*3;i++){ father[i]=i; } cin>>n; for (int o=0;o<n;o++){ int num; scanf("%s %d",temp,&num); int length = strlen(temp); for (int i=0;i<num;i++){ int start ; scanf("%d",&start); int now = father[start]; while (now<start+length){ ans[now]=temp[now-start]; father[now]=find(now+1); now=father[now]; } maxlength = max (maxlength,start+length); } } for (int i=1;i<maxlength;i++){ if (ans[i]>='a'&&ans[i]<='z'){ cout<<ans[i]; }else{ cout<<'a'; } } return 0;}
阅读全文
0 0
- CodeForces Round #423 Div2C&Div1A(827A) Solution
- CodeForces 498A Round #284 div1A(div2C) Crazy Town
- Codeforces 853A Round#433 Div2C & Div1A Planning:优先队列或堆或排序
- Codeforces Round 245 div1A&div2C Xor-tree dfs暴搜
- Codeforces Round242 div1A&div2C Magic Formulas
- Codeforces Round #250 Div1A Div2C 437C The Child and Toy 贪心
- CodeForces Round#423 Div2D&Div1B(827B) Solution
- [Codeforces Round #286 DIV1A (CF506A)] Mr. Kitayuta, the Treasure Hunter
- [Codeforces Round #310 DIV1A (CF555A)] Case of Matryoshkas
- [Codeforces Round #372 DIV1A (CF715A)] Plus and Square Root
- [Codeforces Round #394 DIV2C (CF761C)] Dasha and Password
- codeforces 426 Div2C 833A The Meaningless Game(二分||数学)
- CodeForces 827C Round#423 Div2E&Div1C Solution:树状数组或其他
- CodeForces 827E Round$423 Div1E Solution:暴力的正确姿势
- Codeforces #Round262 div2C Present
- codeforces#FF DIV2C题DZY Loves Sequences(DP)
- codeforces#FF DIV2C题DZY Loves Sequences(DP)
- Codeforces Round #269 (Div. 2) Solution
- POJ 3166 Jumping Frog 笔记
- 启动mysql问题
- php文件包含+伪协议+文件上传漏洞利用实例
- linux下mysql数据的导出和导入
- Linux系统下的BUG
- CodeForces Round #423 Div2C&Div1A(827A) Solution
- 算法之二项分布(java版)
- @Temporal
- 数据库第十一周学习攻略(第十组)
- MySql-Join语法
- LeetCode(10)--RegularExpresssionMatching
- JAVA 封装、构造函数、this关键字 day7
- jfinal报错The method renderText(String) is undefined for the type HelloController
- Python初识