hdu 2642 (summerIII J) 二维树状数组
来源:互联网 发布:淘宝体检中心进不去 编辑:程序博客网 时间:2024/05/21 06:17
#include<cstdio>#include<cstring>#include<cmath>using namespace std;const int maxn=4000;int c[maxn][maxn],n;char str[10];int lowbit(int x){ return x&(-x);}void update(int i,int j,int val){ for(int x=i;x<maxn;x+=lowbit(x)) for(int y=j;y<maxn;y+=lowbit(y)) { c[x][y]+=val; }}int getsum(int i,int j){ int result=0; for(int x=i;x>0;x-=lowbit(x)) { for(int y=j;y>0;y-=lowbit(y)){ result+=c[x][y]; } } return result;}int main(){ scanf("%d%*c",&n); while(n--) { scanf("%s",str); //printf("n:%d\n",n); if(str[0]=='B') { int x,y; scanf("%d%d%*c",&x,&y); x++; y++; if(getsum(x,y)-getsum(x-1,y)-getsum(x,y-1)+getsum(x-1,y-1)==0) update(x,y,1); } else if(str[0]=='D') { int x,y; scanf("%d%d%*c",&x,&y); x++; y++; if(getsum(x,y)-getsum(x-1,y)-getsum(x,y-1)+getsum(x-1,y-1)==1)//计算某一个点是否亮不能直接用C[][]数组判断,下标不一致,应用getsum来计算。 update(x,y,-1); } else if(str[0]=='Q') { int x1,x2,y1,y2; scanf("%d%d%d%d%*c",&x1,&x2,&y1,&y2); if(x1>x2) { int t=x1; x1=x2; x2=t; } if(y2>y1) { int t=y1; y1=y2; y2=t; }//x1 y1,x2,y2的大小不确定,需要先行比较排序。 //printf("1:%d\n",getsum(x2+1,y1+1)); //printf("2:%d\n",getsum(x1+1,y1+1)); //printf("3:%d\n",getsum(x2+1,y2+1)); //printf("4:%d\n",getsum(x1+1,y2+1)); int sum=(getsum(x2+1,y1+1)-getsum(x1,y1+1))-(getsum(x2+1,y2)-getsum(x1,y2));//边界上的点直接做减法会有算不上的,所以把区间点边界点减一,把区间边界点包括进去。 printf("%d\n",sum); } } return 0;}
阅读全文
0 0
- hdu 2642 (summerIII J) 二维树状数组
- HDU 2642 二维树状数组
- hdu 2642 二维树状数组
- HDU 2642 二维树状数组
- poj 3264 (summerIII O) j树状数组 ST表(区间最值查询)
- hdu 2642stars(二维树状数组)
- HDU 2642 stars 二维树状数组
- HDU 2642 二维树状数组问题
- hdu 2642 stars (二维树状数组)
- HDU 2642 Stars (二维树状数组)
- HDU 2642 Stars(二维树状数组)
- hdu 2642 Stars(二维树状数组)
- hdu- 2642 Stars 二维树状数组
- HDU 2642 Stars 二维树状数组应用
- HDU 2642(树状数组模板二维)
- HDU 2642 Stars 二维树状数组
- HDU 2642 Stars [二维树状数组]【数据结构】
- hdu 2642 star(二维树状数组)
- Til the Cows Come Home
- Password
- 组合数求模
- OPNET LINK : fatal error LNK1181如何解决
- Fox And Two Dots
- hdu 2642 (summerIII J) 二维树状数组
- 【GRE】做题记录和总结
- 楼房重建
- PRML:二元变量分布
- Android 图片浏览功能简单实现(画廊效果实现,支持放大缩小)
- 通过Android Studio查看SDK源码
- Python3.6笔记之腌制泡菜(pickle模块的用法)
- 《Thinking In Algorithm》06.Binary search tree(二叉查找树)
- “使用plt.savefig()保存图片时,一片空白”的解决方法