#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<sstream>
#include<string>
#include<climits>
#include<stack>
#include<set>
#include<bitset>
#include<cmath>
#include<deque>
#include<map>
#include<queue>
#define iinf 2000000000
#define linf 1000000000000000000LL
#define dinf 1e200
#define eps 1e-5
#define all(v) (v).begin(),(v).end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define lng long long
#define sqr(a) ((a)*(a))
#define pii pair<int,int>
#define pll pair<lng,lng>
#define pss pair<string,string>
#define pdd pair<double,double>
#define X first
#define Y second
#define pi 3.14159265359
#define ff(i,xi,n) for(int i=xi;i<=(int)(n);++i)
#define ffd(i,xi,n) for(int i=xi;i>=(int)(n);--i)
#define ffl(i,r) for(int i=head[r];i!=-1;i=edge[i].next)
#define cc(i,j) memset(i,j,sizeof(i))
#define two(x) ((lng)1<<(x))
#define N 1002
#define M 1000000
#define lson l , mid , rt << 1
#define rson mid + 1 , r , rt << 1 | 1
#define Mod n
#define Pmod(x) (x%Mod+Mod)%Mod
using namespace std;
typedef vector<int> vi;
typedef vector<string> vs;
typedef unsigned int uint;
typedef unsigned lng ulng;
template<class T> inline void checkmax(T &x,T y){if(x<y) x=y;}
template<class T> inline void checkmin(T &x,T y){if(x>y) x=y;}
template<class T> inline T Min(T x,T y){return (x>y?y:x);}
template<class T> inline T Max(T x,T y){return (x<y?y:x);}
template<class T> T gcd(T a,T b){return (a%b)==0?b:gcd(b,a%b);}
template<class T> T lcm(T a,T b){return a*b/gcd(a,b);}
template<class T> T Abs(T a){return a>0?a:(-a);}
template<class T> inline T lowbit(T n){return (n^(n-1))&n;}
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}
template<class T> inline bool isPrimeNumber(T n)
{if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;}
int ncase,q,num[N][N],sum[N][N];
inline void update(int x,int y,int add)
{
for(int i=x;i<=1001;i+=lowbit(i))
for(int j=y;j<=1001;j+=lowbit(j))
sum[i][j]+=add;
}
inline int get(int x,int y)
{
int val=0;
for(int i=x;i;i-=lowbit(i))
for(int j=y;j;j-=lowbit(j))
val+=sum[i][j];
return val;
}
int main()
{
scanf("%d",&ncase);
ff(numcase,1,ncase)
{
scanf("%d",&q);
cc(sum,0);
ff(i,1,1001)
ff(j,1,1001)
{
num[i][j]=1;
update(i,j,1);
}
char opt;
printf("Case %d:\n",numcase);
ff(i,1,q)
{
getchar();
scanf("%c",&opt);
if(opt=='S')
{
int x1,x2,y1,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
++x1,++x2,++y1,++y2;
if(x1>x2) swap(x1,x2);
if(y1>y2) swap(y1,y2);
printf("%d\n",get(x2,y2)-get(x2,y1-1)-get(x1-1,y2)+get(x1-1,y1-1));
}
else
if(opt=='A')
{
int x,y,n1;
scanf("%d%d%d",&x,&y,&n1);
++x,++y;
update(x,y,n1);
num[x][y]+=n1;
}
else
if(opt=='D')
{
int x,y,n1;
scanf("%d%d%d",&x,&y,&n1);
++x,++y;
if(num[x][y]<n1) n1=num[x][y];
num[x][y]-=n1;
update(x,y,-n1);
}
else
{
int x1,y1,x2,y2,n1;
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n1);
++x1,++x2,++y1,++y2;
if(num[x1][y1]<n1) n1=num[x1][y1];
num[x1][y1]-=n1;
num[x2][y2]+=n1;
update(x1,y1,-n1);
update(x2,y2,n1);
}
}
}
return 0;
}
hdu 1892 树状数组二维 水
最新推荐文章于 2022-02-24 21:59:13 发布