zoukankan      html  css  js  c++  java
  • ZOJ--1610-Count the Colors

    题目链接:ZOJ--1610-Count the Colors

    要注意 更新区间的时候 如果是

    1 3 1

    1 2 2

    3 4 3

    这种情况的时候应该是三种颜色

    要注意 0

    #include<iostream>
    #include<algorithm>
    #include<cmath>
    #include<cstring>
    using namespace std;
    #define maxn 80000
    int a[maxn],b[maxn],c[maxn],mx;
    int ll[maxn],rr[maxn],zz[maxn];
    void init(){
       memset(a,-1,sizeof(a));
       memset(b,-1,sizeof(b));
       memset(c,0,sizeof(c));
    }
    void lazy(int in){
       if(a[in]>=0){
          a[in*2]=a[in];
          a[in*2+1]=a[in];
          a[in]=-1;
       }
    }
    void updata(int l,int r,int x,int y,int va,int in){
      if(x<l||r<y) return ;
      if(l==x&&r==y){
         a[in]=va;
         return ;
      }
      lazy(in);
      int mid=(l+r)/2;
      if(x>mid){
         updata(mid+1,r,x,y,va,in*2+1);
      }else if(y<=mid){
         updata(l,mid,x,y,va,in*2);
      }else{
         updata(l,mid,x,mid,va,in*2);
         updata(mid+1,r,mid+1,y,va,in*2+1);
      }
      //cout<<l<<endl;
    }
    int query(int l,int r,int x,int in){
       //cout<<"1222"<<endl;
       if(l==r){
          return a[in];
       }
       lazy(in);
       int mid=(l+r)/2;
       if(x>mid){
         return query(mid+1,r,x,in*2+1);
       }else return query(l,mid,x,in*2);
    }
    int main(){
      int n;
      while(cin>>n&&n){
         init();
         mx=-1;
         for(int j=0;j<n;j++){
             cin>>ll[j]>>rr[j]>>zz[j];
             mx=max(mx,rr[j]);
             if(mx>8000) mx=8000;
             rr[j]=min(8000,rr[j]);
             if(ll[j]+1>rr[j]){
                rr[j]++;
             }
             //updata(1,mx,x+1,y+1,z,1);
         }
         mx=8000;
         for(int j=0;j<n;j++){
             updata(1,mx,ll[j]+1,rr[j],zz[j],1);
         }
         //cout<<query(1,mx,434+1,1)<<endl;
         for(int j=1;j<=mx;j++){
            b[j]=query(1,mx,j,1);
            //if(b[j]==0)cout<<j<<endl;
         }
         int l=1;
         while(l<=mx){
             int z=b[l];
             int j;
             if(z==-1){
                l++;
                continue;
             }
             for(j=l;j<=mx;j++){
                if(b[j]!=z) break;
             }
    
             l=j;
             c[z]++;
         }
    
        // cout<<c[1]<<endl;
         for(int j=0;j<=mx;j++){
            if(c[j]){
               cout<<j<<" "<<c[j]<<endl;
            }
         }
         cout<<endl;
      }
      return 0;
    }
  • 相关阅读:
    第11次作业
    第十次实验
    第九次作业
    第八次实验
    第七次作业
    第六次作业
    作业
    JAVA实验三
    JAVA实验二
    JAVA实验一
  • 原文地址:https://www.cnblogs.com/Dvelpro/p/9903515.html
Copyright © 2011-2022 走看看