zoj-1610-Count the Colors-线段树-区域更新,单点查询
来源:互联网 发布:中国第四人口普查数据 编辑:程序博客网 时间:2024/06/07 03:56
线段树的区域更新,然后单点查询。
x1 x2 c:区域更新x1-x2为c。
全部染色之后,从0-8000依次查询每个点的颜色。然后存贮每一种颜色有几块。
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<math.h>using namespace std;#define lmin 0#define rmax 8000#define lson l,(l+r)/2,rt<<1#define rson (l+r)/2+1,r,rt<<1|1#define root lmin,rmax,1#define maxn 10000int cl[maxn*4];int num[maxn];void push_up(int rt){}void push_down(int rt){ if(cl[rt]!=-1) { cl[rt<<1]=cl[rt]; cl[rt<<1|1]=cl[rt]; cl[rt]=-1; }}void update(int ll,int rr,int x,int l,int r,int rt){ if(l>rr||r<ll)return; if(ll<=l&&rr>=r) { // cout<<l<<"-"<<r<<"-"<<rt<<"-"<<x<<endl; cl[rt]=x; return; } push_down(rt); update(ll,rr,x,lson); update(ll,rr,x,rson);}int query(int st,int l,int r,int rt){ if(r<st)return 0; if(l>st)return 0; if(l==r&&st==l)return cl[rt]; if(l<=st&&r>=st&&cl[rt]!=-1)return cl[rt]; return query(st,lson)+query(st,rson);}int main(){ int n,l,r,c; while(~scanf("%d",&n)) { memset(cl,-1,sizeof(cl)); memset(num,0,sizeof(num)); while(n--) { scanf("%d%d%d",&l,&r,&c); update(l,r-1,c,root); } int y=-1; for(int i=0;i<=8000;i++) { int x=query(i,root); //cout<<x<<"-"<<endl; // getchar(); if(x==y)continue; y=x; if(x>=0)num[x]++; } for(int i=0;i<=8000;i++) { if(num[i]) { printf("%d %d\n",i,num[i]); } } cout<<endl; } return 0;}
0 0
- zoj-1610-Count the Colors-线段树-区域更新,单点查询
- ZOJ 1610 Count the Colors 线段树 成段更新 单点求值
- zoj 1610 Count the Colors(线段树延迟更新)
- ZOJ 1610Count the Colors 线段树_区间更新
- ZOJ 1610 Count the Colors(线段树区间更新)
- zoj 1610 Count the Colors(线段树 区间更新)
- ZOJ 1610 Count the Colors (线段树区间更新)
- zoj 1610 Count the Colors(线段树 区间更新)
- zoj 1610 Count the Colors 线段树 区间更新
- ZOJ 1610Count the Colors//线段树
- zoj 1610 Count the Colors【线段树】
- zoj 1610 Count the Colors[线段树]
- 【线段树】Count the Colors (zoj 1610)
- zoj 1610 Count the Colors(线段树)
- zoj 1610 Count the Colors 线段树
- ZOJ - 1610 Count the Colors(线段树)
- ZOJ 1610 Count the Colors【线段树】
- ZOJ----1610-Count the Colors(线段树)
- JAVA List用法
- 解决EditText点击两次才能输入的问题
- android adapter 调用notifyDataSetChanged 无效
- Linux mint 16安装中文输入法
- 实用的JavaScript(持续添加)
- zoj-1610-Count the Colors-线段树-区域更新,单点查询
- 黑马程序员_集合(一)_List、Set
- Log4j简介
- 黑马程序员_集合(二)_Map
- android List,HashMap,Iterator
- hdu-1166-敌兵布阵-线段树-单点更新,区域查询
- Java Socket编程总结
- 2 problems (2 errors)make[2]: *** [bin/zabbix-java-gateway-2.0.2.jar] Error 255
- 黑马程序员_IO流(一)