zoj 1610(线段树染色问题)
来源:互联网 发布:怎么找淘宝模特 编辑:程序博客网 时间:2024/06/02 06:37
题意:染色后求一段区间上各个颜色的段数
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;struct node{ int l,r,w,f;}tree[8005*4+5];int a,b,x,num[8005],last;void build(int l,int r,int k){ tree[k].l=l;tree[k].r=r; tree[k].w=-1; tree[k].f=-1; if(l==r) return ; int mid=(l+r)/2; build(l,mid,k*2); build(mid+1,r,k*2+1);}void down(int k){ tree[k*2].w=tree[k].f; tree[k*2+1].w=tree[k].f; tree[k*2].f=tree[k].f; tree[k*2+1].f=tree[k].f; tree[k].f=-1;}void change(int k){ if(tree[k].l>=a&&tree[k].r<=b) { tree[k].w=x; tree[k].f=x; return ; } if(tree[k].f!=-1) down(k); int mid=(tree[k].l+tree[k].r)/2; if(mid>=a)change(k*2); if(mid<b)change(k*2+1); if(tree[k*2].w==tree[k*2+1].w) tree[k].w=tree[k*2].w; else tree[k].w=-1;}void query(int k){ if(tree[k].w!=-1||tree[k].l==tree[k].r) { if(tree[k].w!=last) { num[tree[k].w]++; } last=tree[k].w; return ; } if(tree[k].f!=-1)down(k); int mid=(tree[k].r+tree[k].l)/2; query(k*2); query(k*2+1);}int main(){ int n; while(cin>>n) { last=-1; build(1,8000,1); memset(num,0,sizeof(num)); for(int i=0;i<n;i++) { scanf("%d%d%d",&a,&b,&x); a++; change(1); } query(1); for(int i=0;i<=8000;i++) { if(num[i]!=0) printf("%d %d\n",i,num[i]); } puts(""); }}
阅读全文
0 0
- zoj 1610(线段树染色问题)
- ZOJ 1610 Count the Colors 线段树 染色问题
- ZOJ 1610Count the Colors 线段树区间染色问题
- zoj 1610 Count the Colors(线段树染色)
- ZOJ 1610 Count the Colors (线段树区间染色)
- ZOJ 1610 线段树区间染色
- zoj 1610 Count the Colors 线段树区间更新——染色问题
- ZOJ 1610Count the Colors(线段树+区间染色)
- ZOJ 1610 Count the Colors(线段树区间染色)
- Count Color(线段树+染色问题)
- ZOJ 1610 Count the Colors(线段树——区间更新)(成段染色)
- zoj 1610 Count the Colors(线段树)(成段更新染色)
- 【线段树区间更新 && 染色】ZOJ
- 线段树--Color the ball(多次染色问题)
- poj 2777 Count Color(线段树+染色问题)
- POJ-2777 Count Color(线段树,区间染色问题)
- zoj 1610 Count the Colors(线段树,成段更新染色)
- zoj 1610 Count the Colors 线段树,成段更新染色
- poj1258 Agri-Net
- 36. 数据结构笔记之三十六赫夫曼树
- android的权限permission
- Matlab常用工具箱的调用命令
- 单链表
- zoj 1610(线段树染色问题)
- linux 内存管理基础
- git杂记
- 准备Java面试之——Java SE基础知识解答(三)
- nginx简易教程
- python列表笔记(功能)
- [BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理(状压dp)
- 第三周项目三 求集合并集
- MATLAB嵌套函数的应用