2015
09-17

# Hyperspace

The great Mr.Smith has invented a hyperspace particle generator. The device is very powerful. The device can generate a hyperspace. In the hyperspace, particle may appear and disappear randomly. At the same time a great amount of energy was generated.
However, the device is in test phase, often in a unstable state. Mr.Smith worried that it may cause an explosion while testing it. The energy of the device is related to the maximum manhattan distance among particle.
Particles may appear and disappear any time. Mr.Smith wants to know the maxmium manhattan distance among particles when particle appears or disappears.

The input contains several test cases, terminated by EOF.
In each case: In the first line, there are two integer q(number of particle appear and disappear event, ≤60000) and k(dimensions of the hyperspace that the hyperspace the device generated, ≤5). Then follows q lines. In each line, the first integer ‘od’ represents the event: od = 0 means this is an appear
event. Then follows k integer(with absolute value less then 4 × 107). od = 1 means this is an disappear event. Follows a integer p represents the disappeared particle appeared in the pth event.

The input contains several test cases, terminated by EOF.
In each case: In the first line, there are two integer q(number of particle appear and disappear event, ≤60000) and k(dimensions of the hyperspace that the hyperspace the device generated, ≤5). Then follows q lines. In each line, the first integer ‘od’ represents the event: od = 0 means this is an appear
event. Then follows k integer(with absolute value less then 4 × 107). od = 1 means this is an disappear event. Follows a integer p represents the disappeared particle appeared in the pth event.

10 2
0 208 403
0 371 -180
1 2
0 1069 -192
0 418 -525
1 5
1 1
0 2754 635
0 -2491 961
0 2954 -2516

0
746
0
1456
1456
1456
0
2512
5571
8922

(x1-x2) + (y1-y2), (x1-x2) + (y2-y1), (x2-x1) + (y1-y2), (x2-x1) + (y2-y1)

(x1+y1) – (x2+y2), (x1-y1) – (x2-y2), (-x1+y1) – (-x2+y2), (-x1-y1) – (-x2-y2)

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
#define maxn 60002
int maps[maxn][6];
multiset<int>se[1<<5];
multiset<int>::iterator i1,i2;
int main()
{
int i,j,leap,x,n,m,a;
while(~scanf("%d%d",&n,&m))
{
for(i=0;i<(1<<5);i++)
se[i].clear();
for(i=1;i<=n;i++)
{
scanf("%d",&leap);
if(leap==0)
{
for(j=0;j<m;j++)
{
scanf("%d",&maps[i][j]);
}
for(a=0;a<(1<<m);a++)
{
int as;
as=0;
for(j=0;j<m;j++)
{
if(a&(1<<j))as+=maps[i][j];
else as-=maps[i][j];
}
se[a].insert(as);
}
}
else
{
scanf("%d",&x);
for(a=0;a<(1<<m);a++)
{
int as;
as=0;
for(j=0;j<m;j++)
{
if(a&(1<<j))as+=maps[x][j];
else as-=maps[x][j];
}
i1=se[a].find(as);
se[a].erase(i1);
}
}
int ans=0;
for(a=0;a<(1<<m);a++)
{
i1=se[a].begin();
i2=se[a].end();
i2--;
ans=max(ans,(*i2)-(*i1));
}
cout<<ans<<endl;
}
}
return 0;
}