Stars

http://acm.hdu.edu.cn/showproblem.php?pid=2642

C++版本一

树状数组

/*
*@Author:   STZG
*@Language: C++
*/
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=1000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int ans,cnt,flag,temp;
int c[N][N];
int a[N][N];
char str[2];
int x,y,x2,y2;
int lowbit(int x){
    return x&(-x);
}
void updata(int x,int y,int k){
    for(int i = x ; i > 0 ; i-=lowbit(i))
        for(int j = y ; j > 0 ; j-=lowbit(j))
           c[i][j]+=k;
}
int sum(int x,int y){
    int ans = 0 ;
    for(int i = x ; i < N ; i+= lowbit(i))
        for(int j = y ; j < N ; j+= lowbit(j)){
            ans += c[i][j];
    }

    return ans;
}
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    while(~scanf("%d",&m)){
        while(m--){
            scanf("%s",str);
            if(str[0]=='B'){
                scanf("%d%d",&x,&y);
                if(a[x][y])continue;
                a[x][y]=1;
                updata(x+1,y+1,1);
            }else if(str[0]=='D'){
                scanf("%d%d",&x,&y);
                if(a[x][y]==0)continue;
                a[x][y]=0;
                updata(x+1,y+1,-1);
            }else{
                scanf("%d%d%d%d",&x,&x2,&y,&y2);
                x++;
                y++;
                x2++;
                y2++;
                if(x>x2)swap(x,x2);
                if(y>y2)swap(y,y2);
                cout<

 

你可能感兴趣的:(#,C++)