zoukankan      html  css  js  c++  java
  • poj 2777 Count Color 夜

    http://poj.org/problem?id=2777

    不多说了 和贴海报那题一样 http://www.cnblogs.com/liulangye/archive/2012/06/11/2545349.html

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<queue>
    #include<algorithm>
    #include<vector>
    using namespace std;
    const int N=100005;
    struct node
    {
        int k;
        int l,r;
    }mem[N*3];
    bool out[32];
    int ans;
    void build(int x,int l,int r)
    {
        mem[x].k=0;
        mem[x].l=l;
        mem[x].r=r;
        if(mem[x].l==mem[x].r)
        return;
        int mid=(l+r)>>1;
        build(x*2,l,mid);
        build(x*2+1,mid+1,r);
    }
    void paint(int x,int l,int r,int color)
    {
        if(mem[x].l==l&&mem[x].r==r)
        {
            mem[x].k=color;
            return ;
        }
        if(mem[x].k>0)
        {
            mem[x*2].k=mem[x].k;
            mem[x*2+1].k=mem[x].k;
            mem[x].k=0;
        }
        int mid=(mem[x].l+mem[x].r)>>1;
        if(r<=mid)
        {
            paint(x*2,l,r,color);
        }
        else if(l>mid)
        {
            paint(x*2+1,l,r,color);
        }
        else
        {
            paint(x*2,l,mid,color);
            paint(x*2+1,mid+1,r,color);
        }
    }
    void findcolor(int x,int l,int r)
    {//cout<<x<<" "<<mem[x].l<<" "<<mem[x].r<<" "<<mem[x].k<<endl;
        if(mem[x].k>0)
        {
            if(out[mem[x].k]==false)
            {
                out[mem[x].k]=true;
                ++ans;
            }
            return ;
        }
        int mid=(mem[x].l+mem[x].r)>>1;
        if(r<=mid)
        {
            findcolor(x*2,l,r);
        }
        else if(l>mid)
        {
            findcolor(x*2+1,l,r);
        }
        else
        {
            findcolor(x*2,l,mid);
            findcolor(x*2+1,mid+1,r);
        }
    }
    int main()
    {
        int L,T,O;
        while(scanf("%d %d %d",&L,&T,&O)!=EOF)
        {
            build(1,1,L);
            mem[1].k=1;
            char c;
            int l,r,color;
            while(O--)
            {
                getchar();
                scanf("%c",&c);
                if(c=='C')
                {
                  scanf("%d %d %d",&l,&r,&color);
                  paint(1,l,r,color);
                }
                else
                {
                  scanf("%d %d",&l,&r);
                  memset(out,false,sizeof(out));
                  ans=0;
                  findcolor(1,l,r);
                  printf("%d\n",ans);
                }
            }
    
        }
        return 0;
    }
    
  • 相关阅读:
    Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (二) —— SQLite
    理解 Continuation
    99种用Racket说I love you的方式
    Racket Cheat Sheet
    scheme 教程 #lang racket
    开始学习Scheme
    MIT Scheme 的基本使用
    CPS变换
    SECD machine
    scheme 之门
  • 原文地址:https://www.cnblogs.com/liulangye/p/2545566.html
Copyright © 2011-2022 走看看