zoukankan      html  css  js  c++  java
  • Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C 并查集

    C. String Reconstruction
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 strings ti.

    You are to reconstruct lexicographically minimal string s such that it fits all the information Ivan remembers. Strings ti and string s consist of small English letters only.

    Input

    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 exceed 106, 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.

    Output

    Print lexicographically minimal string that fits all the information Ivan remembers.

    Examples
    Input
    3
    a 4 1 3 5 7
    ab 2 1 5
    ca 1 4
    Output
    abacaba
    Input
    1
    a 1 3
    Output
    aaa
    Input
    3
    ab 1 1
    aba 1 3
    ab 2 3 5
    Output
    ababab
    题意:n行 每行先给你一个字符串str 以及接下来的x位置 表示以某个位置开始的字符串部分为str 输出满足以上要求的字典序最小的字符串
    题解:stl怼爆内存 这里用到了并查集 对于每个位置i的字符当确认之后 使得fa[i]=i+1 则不需要每次都遍历更新每个位置的字符 寻找其在范围内的fa即可
     1 #pragma comment(linker, "/STACK:102400000,102400000")
     2 #include <cstdio>
     3 #include <iostream>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <algorithm>
     7 #include <cmath>
     8 #include <cctype>
     9 #include <map>
    10 #include <set>
    11 #include <queue>
    12 #include <bitset>
    13 #include <string>
    14 #include <complex>
    15 #define ll __int64
    16 using namespace std;
    17 int fa[2000006];
    18 char ans[2000006];
    19 int find(int x)
    20 {
    21     if(fa[x]==x)
    22         return x;
    23     else
    24         return fa[x]=find(fa[x]);
    25 }
    26 int n;
    27 char a[1000006];
    28 int main()
    29 {
    30     scanf("%d",&n);
    31     int exm;
    32     int zong=0;
    33     for(int i=1;i<=2000000;i++){
    34         ans[i]='a';
    35         fa[i]=i;
    36         }
    37     for(int i=1; i<=n; i++){
    38         scanf("%s",a);
    39         int len=strlen(a);
    40         scanf("%d",&exm);
    41         for(int j=1;j<=exm;j++){
    42             int ss;
    43             scanf("%d",&ss);
    44             int x=ss;
    45             zong=max(zong,ss+len-1);
    46             while(x<=(ss+len-1))
    47             {
    48                 ans[x]=a[x-ss];
    49                 fa[x]=x+1;x=find(x);
    50             }
    51         }
    52     }
    53     for(int i=1;i<=zong;i++)
    54         printf("%c",ans[i]);
    55     printf("
    ");
    56     return 0;
    57 }
  • 相关阅读:
    黑盒测试方法用例设计详解
    跨域
    HTTP Referer
    Java抽象类和接口
    深入理解Java垃圾回收机制
    Java异常处理机制
    hash
    JUint4的下载、配置及对一个算法编写单元测试用例(测试多组数据每组多个参数)
    get和post的区别
    Mac 文档阅读软件Dash软件破解版
  • 原文地址:https://www.cnblogs.com/hsd-/p/7173074.html
Copyright © 2011-2022 走看看