• HDU


    Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B is painting. To prevent him from drawing messy painting, Little D asks you to write a program to maintain following operations. The specific format of these operations is as follows.

    0 : clear all the points.

    1 x y c : add a point which color is c at point (x,y(x,y) .

    2 x 1  y1 2  y2 : count how many different colors in the square (1,y1(1,y1) and (x,y2(x,y2) . That is to say, if there is a point (a,b(a,b) colored c , that 1a1≤a≤x and b2  y1≤b≤y2 , then the color c should be counted.

    3 : exit.

    InputThe input contains many lines.

    Each line contains a operation. It may be '0', '1 x y c' ( 1x,y10 ,0c50 1≤x,y≤106,0≤c≤50 ), '2 x y1 y2' (1x,,10 6  1≤x,y1,y2≤106 ) or '3'.

    x,y,c,y1,yx,y,c,y1,y2 are all integers.

    Assume the last operation is 3 and it appears only once.

    There are at most 150000 150000 continuous operations of operation 1 and operation 2.

    There are at most 10 10 operation 0.

    OutputFor each operation 2, output an integer means the answer .
    Sample Input

    0
    1 1000000 1000000 50
    1 1000000 999999 0
    1 1000000 999999 0
    1 1000000 1000000 49
    2 1000000 1000000 1000000
    2 1000000 1 1000000
    0
    1 1 1 1
    2 1 1 2
    1 1 2 2
    2 1 1 2
    1 2 2 2
    2 1 1 2
    1 2 1 3
    2 2 1 2
    2 10 1 2
    2 10 2 2
    0
    1 1 1 1
    2 1 1 1
    1 1 2 1
    2 1 1 2
    1 2 2 1
    2 1 1 2
    1 2 1 1
    2 2 1 2
    2 10 1 2
    2 10 2 2
    3

    Sample Output

    2
    3
    1
    2
    2
    3
    3
    1
    1
    1
    1
    1
    1
    1

    题意:给定一个1e6*1e6的矩阵,有四种操作,0是清空矩阵;1是给某点加一个颜色c;2是查询某个区间(1,y1)到(x2,y2)的颜色数,3是退出。

    思路:由于矩阵位置的特殊性,都是x=1开始,那么我们就是查询每种颜色在区间(y1,y2)是否有点的最小值小于x2。 用线段树维护区间最小值,动态开点。

    (日后来补CDQ分治。

    #include<bits/stdc++.h>
    #define rep(i,a,b) for(int i=a;i<=b;i++)
    using namespace std;
    const int maxn=2000010;
    struct in{
        int l,r,v;
        in(){l=r=v=0;}
    }s[maxn<<1]; int rt[51],cnt;
    void update(int &Now,int L,int R,int pos,int val)
    {
        if(!Now) Now=++cnt,s[Now].v=val;
        s[Now].v=min(s[Now].v,val);
        if(L==R) return ; int Mid=(L+R)>>1;
        if(pos<=Mid) update(s[Now].l,L,Mid,pos,val);
        else update(s[Now].r,Mid+1,R,pos,val);
    }
    bool query(int Now,int L,int R,int l,int r,int pos)
    {
        if(!Now) return false;
        if(l<=L&&r>=R) return s[Now].v<=pos;
        int Mid=(L+R)>>1;
        if(l<=Mid) if(query(s[Now].l,L,Mid,l,r,pos)) return true;
        if(r>Mid) if(query(s[Now].r,Mid+1,R,l,r,pos)) return true;
        return false;
    }
    int main()
    {
        int opt,x1,y1,x2,y2,c;
        while(scanf("%d",&opt)){
            if(opt==0){
                rep(i,0,50) rt[i]=0;
                rep(i,1,cnt) s[i].l=s[i].r=s[i].v=0;cnt=0;
            }
            else if(opt==1){
                scanf("%d%d%d",&x1,&y1,&c);
                update(rt[c],1,1000000,y1,x1);
            }
            else if(opt==2){
                scanf("%d%d%d",&x2,&y1,&y2); int ans=0;
                rep(i,0,50) ans+=query(rt[i],1,1000000,y1,y2,x2);
                printf("%d
    ",ans);
            }
            else break;
        }
        return 0;
    }
  • 相关阅读:
    Jenkins tomcat 一键发布 (三)
    Jenkins docker 一键发布 (二)
    Jenkins docker 一键发布 (一)
    jenkins构建maven项目:找不到本地依赖包的解决办法
    Linux socket编程示例
    Linux虚拟机环境搭建
    Linux vim 配置
    vs2013 Qt5.7.0环境安装搭建
    Linux下如何生成core dump 文件
    QT5新建工程错误->无法打开源文件QtWidgets/QApplication
  • 原文地址:https://www.cnblogs.com/hua-dong/p/9818498.html
Copyright © 2020-2023  润新知