国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

HDU-2642-Stars(二維樹狀數(shù)組應(yīng)用)

2019-11-11 07:25:11
字體:
供稿:網(wǎng)友

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  題目大意:  二維空間里,初始時(shí)一片空白,有如下幾種操作:  1.B x y  :將坐標(biāo)為(x,y)的地方點(diǎn)亮  2.D x y  :將坐標(biāo)為(x,y)的地方熄滅  3. Q x x1 y y1 :查詢該矩形區(qū)域內(nèi)點(diǎn)亮的星星個(gè)數(shù) 題解:樹狀數(shù)組模板 唯一坑點(diǎn):當(dāng)點(diǎn)(x,y)處已經(jīng)點(diǎn)亮,則不再點(diǎn)亮 熄滅操作雷同。
#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);		}	}}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 吉木乃县| 项城市| 崇信县| 玛曲县| 千阳县| 长丰县| 谢通门县| 香格里拉县| 安顺市| 崇阳县| 札达县| 德格县| 琼结县| 太白县| 公安县| 大连市| 滨海县| 迁安市| 瓦房店市| 阳新县| 安顺市| 宁强县| 古交市| 开封市| 金昌市| 东乡族自治县| 通渭县| 定日县| 保康县| 张掖市| 福贡县| 陕西省| 平山县| 宁海县| 东阳市| 泊头市| 黑河市| 台湾省| 普格县| 丹巴县| 屏边|