麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

HDU-2642-Stars(二維樹狀數組應用)

2019-11-14 09:14:20
字體:
來源:轉載
供稿:網友

Stars

Time Limit: 5000/2000 MS (java/Others)    Memory Limit: 32768/65536 K (Java/Others)Total Submission(s): 1718    Accepted Submission(s): 725PRoblem DescriptionYifenfei is a romantic guy and he likes to count the stars in the sky.To make the problem easier,we considerate the sky is a two-dimension plane.Sometimes the star will be bright and sometimes the star will be dim.At first,there is no bright star in the sky,then some information will be given as "B x y" where 'B' represent bright and x represent the X coordinate and y represent the Y coordinate means the star at (x,y) is bright,And the 'D' in "D x y" mean the star at(x,y) is dim.When get a query as "Q X1 X2 Y1 Y2",you should tell Yifenfei how many bright stars there are in the region correspond X1,X2,Y1,Y2.There is only one case. InputThe first line contain a M(M <= 100000), then M line followed.each line start with a Operational character.if the character is B or D,then two integer X,Y (0 <=X,Y<= 1000)followed.if the character is Q then four integer X1,X2,Y1,Y2(0 <=X1,X2,Y1,Y2<= 1000) followed. OutputFor each query,output the number of bright stars in one line. Sample Input
5B 581 145B 581 145Q 0 600 0 200D 581 145Q 0 600 0 200 Sample Output
10  題目大意:  二維空間里,初始時一片空白,有如下幾種操作:  1.B x y  :將坐標為(x,y)的地方點亮  2.D x y  :將坐標為(x,y)的地方熄滅  3. Q x x1 y y1 :查詢該矩形區域內點亮的星星個數 題解:樹狀數組模板 唯一坑點:當點(x,y)處已經點亮,則不再點亮 熄滅操作雷同。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 1005int a[maxn][maxn],b[maxn][maxn];int lowbit(int x){	return x&-x;}void update(int x,int y,int z){	int i,j;	for(i=x;i<=maxn;i+=lowbit(i))		for(j=y;j<=maxn;j+=lowbit(j))			a[i][j]+=z;}int query(int x,int y){	int sum=0,i,j;	for(i=x;i>0;i-=lowbit(i))		for(j=y;j>0;j-=lowbit(j))			sum+=a[i][j];	return sum;}int  main(){	int n,i,x,y,xx,yy;	scanf("%d",&n);	for(i=1;i<=n;i++)	{		char c[5];		scanf("%s",c);		if(c[0]=='B')		{			scanf("%d%d",&x,&y);			x++;y++;			if(b[x][y])				continue;			update(x,y,1);			b[x][y]=1;		}		else if(c[0]=='D')		{			scanf("%d%d",&x,&y);			x++;y++;			if(!b[x][y])				continue;			update(x,y,-1);			b[x][y]=0;		}		else		{			scanf("%d%d%d%d",&x,&xx,&y,&yy);			x++;y++;			xx++;yy++;			if(x<xx)				swap(x,xx);			if(y<yy)				swap(y,yy);			int ans=query(x,y)-query(x,yy-1)-(query(xx-1,y)-query(xx-1,yy-1));			printf("%d/n",ans);		}	}}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 无码av女优 | 国产精品久久久久一区二区 | 国产91九色 | av视在线| 久久精品a一级国产免视看成人 | 国产在线地址 | 视频在线中文字幕 | 色操网| 激情综合在线观看 | 久久精品一二三区白丝高潮 | 99国语露脸久久精品国产ktv | 激情久久婷婷 | 嗯哈~不行好大h双性 | 国产精品视频自拍 | 亚洲午夜不卡 | 日韩精品中文字幕在线播放 | 国产成人精品一区二区视频免费 | 少妇淫片免费一级毛片 | 精品三区视频 | 最新午夜综合福利视频 | 成人午夜免费在线视频 | 法国极品成人h版 | 亚洲人成中文字幕在线观看 | 91精品国产综合久久婷婷香 | 一级做a爰片性色毛片2021 | 国产日韩在线观看一区 | 久久精品视频日本 | 午夜视频在线看 | 久久蜜桃香蕉精品一区二区三区 | h视频免费观看 | 亚洲精品a在线观看 | 国产精品久久久网站 | 欧美成人免费在线视频 | 国产视频在线观看免费 | 欧美一级黄色影院 | 欧美日韩高清一区二区三区 | 一本色道久久综合亚洲精品小说 | 少妇一级淫片免费看 | 成人福利在线看 | 一级黄色av电影 | 九九热视频这里只有精品 |