sgu 177 分类: sgu 2015-04-25 22:38 28人阅读 评论(0) 收藏
开
没加
时间复杂度
#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
}
版权声明:本文为博主原创文章,未经博主允许不得转载。