sgu 177 分类: sgu 2015-04...


n 个线段树,然后每行暴搞即可。

没加 inline 就过了。。。奇怪。。。
时间复杂度 O(nlog2nm+nn)



#include<map>
#include<stack>
#include<queue>
#include<ctime>
#include<cmath>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
#define L(x) ((x)<<1)
#define R(x) ((x)<<1|1)

const int MAXN = 1005, Black = 1, White = 2;

int n, m;
int tree[MAXN][MAXN<<2] = {0}; 

void PushDown(int *t,int x)
{
    if(t[x]) t[L(x)] = t[R(x)] = t[x], t[x] = 0;
}
void Change(int *t,int l,int r,int ll,int rr,int si,int col)
{
    if(l == ll && r == rr)
         t[si] = col;
    else
    {
        PushDown(t,si);

        int mid = (ll + rr)>>1;
        if(r <= mid)
          Change(t,l,r,ll,mid,L(si),col);
        else if(l > mid)
          Change(t,l,r,mid+1,rr,R(si),col);
        else
          Change(t,l,mid,ll,mid,L(si),col),
          Change(t,mid+1,r,mid+1,rr,R(si),col);    
    }
}
void Solve(int xl,int xr,int yl,int yr,int color)
{
    for(int i = xl; i <= xr; i++)
      Change(tree[i],yl,yr,1,n,1,color);
}
int Count(int *t,int ll,int rr,int si)
{
    if(t[si]) return (t[si]==White)?(rr-ll+1):0;
    else
    {
     int mid = (ll + rr)>>1, ret = 0;   
     if(ll <= mid) ret +=  Count(t,ll,mid,L(si));
     if(mid < rr) ret += Count(t,mid+1,rr,R(si));
     return ret;
    }
}
int GetAns()
{
    int ret = 0;
    for(int i = 1; i <= n; i++)
       ret += Count(tree[i],1,n,1);
    return ret;   
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("sgu177.in","r",stdin);
    freopen("sgu177.out","w",stdout);
#endif

    std::cin >> n >> m;

    for(int i = 1; i <= n; i++) tree[i][1] = White;

    while(m--)
    {
        int x1,x2,y1,y2;char s[3] = {0};

        std::cin >> x1 >> y1 >> x2 >> y2 >> s;

        if(x1 > x2) std::swap(x1,x2);
        if(y1 > y2) std::swap(y1,y2);

        switch(s[0])
        {
           case 'b': Solve(x1,x2,y1,y2,Black); break;
           case 'w': Solve(x1,x2,y1,y2,White); break;
        }   
    }

    std::cout << GetAns() << std::endl;

#ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
#endif
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/dashgua/p/4723036.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值