bnu 49100:超级线段树
来源:互联网 发布:画家知一作品图片 编辑:程序博客网 时间:2024/04/30 13:19
超级线段树
Time Limit: 5000ms
Memory Limit: 65536KB
64-bit integer IO format: %lld Java class name: MainPrev
Submit Status Statistics Discuss
Nextwhalyzh是一个数据结构弱渣,于是他决定恶补一下。众所周知,线段树可以实现对一个[L,R]区间进行一些操作,比如加上一个数或者求最值等等……一天,whalyzh遇到一道题,需要对一个序列进行M次区间操作,由于操作的种类很多,做着做着whalyzh就晕了。现在,他只想知道M次操作后序列中每个数最后一次被执行的操作是什么?
Input
输入数据有多组。
第一行输入一个整数T(T≤10),表示数据组数。
每组数据第一行为两个整数N(N≤10^6)、M(M≤10^6),分别代表序列长度和操作次数。
接下来M行每行三个整数L、R、P(1≤L≤R≤N, 1≤P≤10^6),代表对区间[L,R]执行了操作P。
Output
每组数据输出N行,第i行输出表示序列第i个数最后执行的操作,如果没有执行过操作输出0。
Sample Input
13 21 2 11 1 2
Sample Output
210仰慕Q神。
先写线段树,被T掉。。。。
从后往前染色,每个点维护到最右端被染色的点,这样从后往前的时候对要操作的点如果被染色了,不能管他,直接跳到最右端没有被染色的点。使用并查集维护。
代码:
#pragma warning(disable:4996)#include <iostream>#include <functional>#include <algorithm>#include <cstring>#include <vector>#include <string>#include <cstdio>#include <cmath>#include <queue>#include <stack>#include <deque>#include <set>#include <map>using namespace std;typedef long long ll;#define INF 0x33ffffff#define eps 1e-8const ll mod = 1000000007;const int maxn = 1e6 + 5;const double PI = acos(-1.0);struct no{int le;int ri;int p;}node[maxn];int n, m;int fa[maxn], col[maxn];stack<int>st;int getfa(int x){while (fa[x] != x){st.push(x);x = fa[x];}while (!st.empty()){fa[st.top()] = x;st.pop();}return x;}void uni(int x, int y){x = getfa(x), y = getfa(y);if (x == y)return;if (x < y){fa[x] = y;}else{fa[y] = x;}}void solve(){int i, j;scanf("%d%d", &n, &m);for (i = 1; i <= n; i++)fa[i] = i;for (i = 1; i <= m; i++){scanf("%d%d%d", &node[i].le, &node[i].ri, &node[i].p);}memset(col, 0, sizeof(col));for (i = m; i >= 1; i--){int le = node[i].le;int ri = node[i].ri;int p = node[i].p;if (col[le]){le = getfa(le) + 1;}while (le <= ri){col[le] = p;if (le > 1 && col[le - 1]){uni(le, le - 1);}if (le < n&&col[le + 1]){uni(le, le + 1);}le = getfa(le) + 1;}}for (i = 1; i <= n; i++){printf("%d\n", col[i]);}}int main(){int t;scanf("%d", &t);while (t--){solve();}return 0;}
0 0
- BNU 49100超级线段树
- bnu 49100:超级线段树
- BNU- 12873 - Generations 线段树
- BNU 12680 Jupiter Atacks! (线段树)
- BNU 1018(线段树+二分)
- BNU A Simple Tree Problem 线段树
- 超级线段树
- BNU - Choosing a camera - 数据结构 (线段树、队列)
- bnuoj 49100超级线段树并查集
- BNU 斩(超级大水题)
- 【BNU Summer Training 2014.08.11】 Nested Segments (线段树,离散化)
- BNU-1018-信息战(四)——战场演练(线段树 better)
- BNU
- [Noi2010] D1T2 超级钢琴 (ST表 线段树 主席树)
- [BZOJ2006][[NOI2010]超级钢琴][优先队列+线段树]
- 超级牛逼的线段树总结 啊哈哈~~~
- [NOI2010]超级钢琴(可持续化线段树)
- bzoj 2006 [NOI2010]超级钢琴 二分答案 可持久化线段树
- java 连接mysql
- Majority Element
- 软件需求分析与IT创新
- C++命名空间
- 第一行代码 读笔③ (Layout ListView)
- bnu 49100:超级线段树
- 【CodeForces】[653A]Bear and Three Balls
- 自己制作Linux驱动调试工具之查看寄存器
- 贪心算法
- 各个类型的范围
- vim 命令图解及vim使用技巧
- php学习笔记-后台模块
- 通用算法包(记录)
- 架构高性能网站秘笈(三)——浏览器缓存