• CF869E The Untended Antiquity 解题报告


    CF869E The Untended Antiquity

    题目描述

    ( ext{Adieu l'ami}).

    Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around the abandoned Eikou Cram School building, Oshino's makeshift residence.

    The space is represented by a rectangular grid of (n imes m) cells, arranged into (n) rows and (m) columns. The (c) -th cell in the (r) -th row is denoted by ((r,c)) .

    Oshino places and removes barriers around rectangular areas of cells.

    Specifically, an action denoted by " (1 r_{1} c_{1} r_{2} c_{2})" means Oshino's placing barriers around a rectangle with two corners being ((r_{1},c_{1})) and ((r_{2},c_{2})) and sides parallel to squares sides.

    Similarly, " (2 r_{1} c_{1} r_{2} c_{2}) " means Oshino's removing barriers around the rectangle. Oshino ensures that no barriers staying on the ground share any common points, nor do they intersect with boundaries of the (n imes m) area.

    Sometimes Koyomi tries to walk from one cell to another carefully without striding over barriers, in order to avoid damaging various items on the ground. " (3 r_{1} c_{1} r_{2} c_{2})" means that Koyomi tries to walk from ((r_{1},c_{1})) to ((r_{2},c_{2})) without crossing barriers.

    And you're here to tell Koyomi the feasibility of each of his attempts.

    输入输出格式

    输入格式:

    The first line of input contains three space-separated integers (n) , (m) and (q) ( (1<=n,m<=2500) , (1<=q<=100000) ) — the number of rows and columns in the grid, and the total number of Oshino and Koyomi's actions, respectively.

    The following q q lines each describes an action, containing five space-separated integers (t) , (r_{1}) , (c_{1}) , (r_{2}) , (c_{2}) ( (1<=t<=3) , (1<=r_{1} , r_{2}<=n) , (1<=c_{1},c_{2}<=m) ) — the type and two coordinates of an action. Additionally, the following holds depending on the value of t t :

    If (t=1) : (2<=r_{1}<=r_{2}<=n-1) , (2<=c_{1}<=c_{2}<=m-1) ;
    If (t=2) : (2<=r_{1}<=r_{2}<=n-1) , (2<=c_{1}<=c_{2}<=m-1) , the specified group of barriers exist on the ground before the removal.
    If (t=3) : no extra restrictions.

    输出格式:

    For each of Koyomi's attempts (actions with (t=3) ), output one line — containing "Yes" (without quotes) if it's feasible, and "No" (without quotes) otherwise.


    这题有几个要注意的条件:围墙不重叠不交叉不堵边界

    可以对一个围墙里面的矩形进行染色。

    查询看颜色是否一样。

    具体来说,拿二维树状数组维护单点问区间改,差分一下

    拿了随机数长整型自动取模wa,模大质数wa,听说不能随机。。

    然后试了试,维护异或和就过了

    注意维护异或和差分的写法。


    Code:

    #include <cstdio>
    #include <cstdlib>
    #include <ctime>
    #define ll long long
    const int N=2505;
    int n,m,q;
    ll s[N][N],tag[N][N];
    void add(int x,int y,ll d)
    {
        for(int i=x;i<=n;i+=i&-i)
            for(int j=y;j<=m;j+=j&-j)
                s[i][j]^=d;
    }
    ll query(int x,int y)
    {
        ll sum=0;
        for(int i=x;i;i-=i&-i)
            for(int j=y;j;j-=j&-j)
                sum^=s[i][j];
        return sum;
    }
    int main()
    {
        srand(19260817);
        scanf("%d%d%d",&n,&m,&q);
        for(int r1,c1,r2,c2,op,i=1;i<=q;i++)
        {
            scanf("%d%d%d%d%d",&op,&r1,&c1,&r2,&c2);
            if(op==1)
            {
                tag[r1][c1]=rand()*rand();
                add(r1,c1,tag[r1][c1]);
                add(r2+1,c2+1,tag[r1][c1]);
                add(r1,c2+1,tag[r1][c1]);
                add(r2+1,c1,tag[r1][c1]);
            }
            else if(op==2)
            {
                add(r1,c1,tag[r1][c1]);
                add(r2+1,c2+1,tag[r1][c1]);
                add(r1,c2+1,tag[r1][c1]);
                add(r2+1,c1,tag[r1][c1]);
            }
            else
            {
                if(query(r1,c1)==query(r2,c2)) puts("Yes");
                else puts("No");
            }
        }
        return 0;
    }
    

    2018.10.11

  • 相关阅读:
    Electron踩坑记录
    TypeScript实现设计模式——生成器模式
    在express中使用ES7装饰器构建路由
    微信小程序下载文件(非图片),并校验扩展名。
    防抖与节流
    yarn
    spark
    docker php-fpm中安装GD库
    thinkphp6 多应用路由遇坑记
    CentOS 7 开启SSH远程登录
  • 原文地址:https://www.cnblogs.com/butterflydew/p/9774855.html
Copyright © 2020-2023  润新知