# Zoj-1610-Count the Colors-line segment tree-region update, single point Query

Source: Internet
Author: User

The region of the Line Segment tree is updated, and then spof queries are performed.

X1 x2 c: Region update x1-x2 is c.

After all the colors are colored, the color of each vertex is queried from 0. Each color is stored in several pieces.

```#include

#include

#include

#include#include

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

=r)    {      //  cout<

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<

=0)num[x]++; } for(int i=0;i<=8000;i++) { if(num[i]) { printf("%d %d\n",i,num[i]); } } cout<

```
Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.