Codeforces 827A/828C String Reconstruction[线段树单点更新]

题意:给了你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]);
	}
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值