Codeforces 827A/828C String Reconstruction[线段树单点更新]
来源:互联网 发布:网易uu加速器mac版 编辑:程序博客网 时间:2024/06/05 06:17
题意:给了你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|1typedef 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 0
- Codeforces 827A/828C String Reconstruction[线段树单点更新]
- Codeforces 827A. String Reconstruction
- CodeForces 828C String Reconstruction
- Codeforces 828 C String Reconstruction
- codeforces 828C. String Reconstruction
- Codeforces 828 C. String Reconstruction 思维
- CodeForces 828C String Reconstruction(思维)
- codeforces 828 c String Reconstruction(扫描线+string)
- Codeforces 525B. Pasha and String【线段树 区间更新 单点查询】
- 线段树专题 A(单点更新)
- Codeforces 828C String Reconstruction【思维+并查集】
- ccnu-线段树-单点更新3-C
- CodeFroces 827A.String Reconstruction
- Codeforces #423-Div. 2-C. String Reconstruction
- Codeforces Round #423 C. String Reconstruction
- Codeforces Round #423 C. String Reconstruction
- 线段树 单点更新
- 线段树单点更新
- 驻极体麦和MEMS麦
- SVM 分类算法
- PHP非递归方式实现无限分类(转载)
- A poem
- 高清加载巨图方案-拒绝压缩图片
- Codeforces 827A/828C String Reconstruction[线段树单点更新]
- LeetCode: 35. Search Insert Position
- Codeforces 827B. High Load 【构造】
- 活动的启动
- 微信小程序文章界面简单布局
- Laravel 及 composer 安装及使用
- 文章标题
- 块级元素内容过长点点显示(XXXX....)
- Oracle安装过后怎么解锁Scott账户