Description
Suppose the fourth generation mobile phone base stations in the Tampere area operate as follows. The area was divided into squares. The squares form an s * s matrix with the rows and columns numbered from 0 to S-1. Each square contains a base station. The number of active mobile phones inside a square can change because a phone was moved from a square to another or a phone is switched on or off. At times, each base station reports the change in the number of active phones to the main base station along with the row And the column of the Matrix.
Write a program, which receives these reports and answers queries on the current total number of active mobile phones I N any rectangle-shaped area. A two-dimensional tree-like array of bare topics, but note that the coordinates should be added one, because starting from 0. The code is as follows:
//The ━━━━━━ of gods and Beasts ━━━━━━//┏┓┏┓//┏┛┻━━━━━━━┛┻┓//┃┃//┃━┃//████━████┃//┃┃//┃┻┃//┃┃//┗━┓┏━┛//┃┃//┃┃//┃┗━━━┓//┃┣┓//┃┏┛//┗┓┓┏━━━━━┳┓┏┛//┃┫┫┃┫┫//┗┻┛┗┻┛////━━━━━━ Feel the ━━━━━━ of Meng Meng//author:whywhy//Created time:2015 July 17 Friday 14:44 13 seconds//File name:1195.cpp#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<time.h>using namespacestd;Const intmaxn=1100;intC[MAXN][MAXN];intN;inlineintLowbit (intx) { returnx& (-x);}voidAddintXintYintd) { intT; while(x<=N) {T=y; while(t<=N) {c[x][t]+=D; T+=lowbit (t); } x+=lowbit (x); }}intQueryintXinty) { intret=0; intT; while(x>0) {T=y; while(t>0) {ret+=C[x][t]; T-=lowbit (t); } x-=lowbit (x); } returnret;}intMain () {//freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout); inta,b,c,d,e; while(1) {scanf ("%d",&a); if(a==1) {scanf (" %d%d%d",&b,&c,&d); Add (b+1, c+1, D); } Else if(a==2) {scanf ("%d %d%d%d",&b,&c,&d,&e); printf ("%d\n", Query (d+1, e+1)-query (d+1, c)-query (b,e+1)+query (b,c)); } Else if(a==0) {scanf ("%d",&N); memset (C,0,sizeof(C)); } Else Break; } return 0;}
View Code
Simple POJ 1195 Mobile phones, a two-dimensional tree-like array.