题意:给了你n个字符串,然后说明这个字符串在什么位置出现了,然后让你输出字典序最小的答案.
分析:
1.首先是答案的长度,根据字典序的定义,长度取,给定的n个字符串出现的最大的(位置+len(i)-1);
2.如何把给定的字符串更新上去, 因为题目保证没有矛盾,所以更新过的点就不用再更新了,这样我们用一个vis数组,表示当前区间是否已经完全更新完,如果更新完了就不管了,没更新完继续单点更新就行了。
3.还有就是有些点可能没被更新到,输出a就行了。
以下是代码
#include<bits/stdc++.h>
using namespace std;
#define _____ ios::sync_with_stdio(false); cin.tie(0);
#define ull unsigned long long
#define ll long long
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
typedef pair<int, int>pii;
typedef pair<ll, ll>pll;
typedef pair<double, double>pdd;
const double eps = 1e-6;
const int MAXN = 350005;
const int MAXM = 5005;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const double FINF = 1000000000000000.0;
const ll MOD = 1000000007;
const double PI = acos(-1);
char ans[2000005];
int vis[8000005];
string s;
void add(int l, int r, int id, int L, int R) {
if (vis[id] == r - l + 1)return;
if (l == r) {
ans[l] = s[l - L];
vis[id] = 1;
return;
}
int mid = (l + r) >> 1;
if (R <= mid)add(lson, L, R);
else if (L > mid)add(rson, L, R);
else
{
add(lson, L, R);
add(rson, L, R);
}
vis[id] = vis[id << 1] + vis[id << 1 | 1];
}
int main()
{
memset(vis, 0, sizeof(vis));
int n, x, maxx = 0; scanf("%d", &n);
for (int i = 0; i <= 2000000; ++i)ans[i] = 'A';
for (int i = 0; i < n; ++i) {
cin >> s;
int t; scanf("%d", &t);
int len = s.size();
while (t--) {
scanf("%d", &x); maxx = max(maxx, x + len - 1);
add(1, 2000000, 1, x, x + len - 1);
}
}
for (int i = 1; i <= maxx; ++i) {
if (ans[i] == 'A')printf("a");
else printf("%c", ans[i]);
}
}