# HDU 5714 拍照 优先队列前后扫 （2016百度之星复赛）

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <iostream>
#include <map>
#define pii pair<int,int>
#define mp(a,b) make_pair<a,b>
#define xx first
#define yy second
#define mem(a) memset( a, 0, sizeof(a) )
using namespace std;
typedef long long ll;

struct ship
{
int x, y, d, z;
}p[100005];
int n;

pii l[100005], r[100005];
int lans[100005], rans[100005];
//此处可用map实现去重功能，不过实际不需要
bool cmp( pii a, pii b )
{
return a.xx > b.xx;
}

void solve()
{
int i, x, y, z, d, cnt = 1, cnt1 = 1, cnt2 = 1;
cin >> n;

for( i = 1; i <= n; i ++ ){
scanf("%d %d %d %d", &x, &y, &z, &d);
if( x+z < y-z ) continue;
p[cnt].x = x;
p[cnt].y = y;
p[cnt].z = z;
p[cnt].d = d;
pii s(x+z, cnt);
if( d == -1 ){
l[cnt1++] = s;
}
else{
r[cnt2++] = s;
}
cnt ++;
}
n = cnt-1;
sort( l+1, l+cnt1, cmp );// 注意！！ sort默认升序排列 优先队列默认大根堆降序排列
sort( r+1, r+cnt2, cmp );
mem(lans);mem(rans);
priority_queue<int>q;
while( !q.empty() ) q.pop();
int tmp = 0;
int res = 0;
for( i = 1; i < cnt1; i ++ ){
int id = l[i].yy;
q.push( p[id].y-p[id].z );
while( !q.empty() && q.top() > l[i].xx ){
q.pop();
}
tmp = q.size();
lans[i] = tmp;
res = max( tmp, res );
}

tmp = 0;
while( !q.empty() ) q.pop();
for( i = 1; i < cnt2; i ++ ){
int id = r[i].yy;
q.push( p[id].y-p[id].z );
while( !q.empty() && q.top() > r[i].xx ){
q.pop();
}
tmp = q.size();
rans[i] = tmp;
res = max( tmp, res );
}

while( !q.empty() ) q.pop();
int j = cnt2-1;
int max1 = 0;
res = 0;
for( i = cnt1-1; i >= 1; i -- ){
while( r[j].xx <= l[i].xx && j >= 1 ){
max1 = max( rans[j], max1 );
j --;
}
res = max( res, max1+lans[i] );
}
printf("%d\n", res);
}

int main()
{
int T, cas = 1;
cin >> T;
while( T -- ){
printf("Case #%d:\n", cas++);
solve();
}
}


#### 2017百度之星 复赛

2017-08-18 21:36:12

#### HDU 6172 and HDU 6185 【线性递推 + 思维 + 板子】

2017-09-03 13:14:19

#### hdu 5714 &&2016 百度之星复赛 1003 拍照(排序+思考)

2016-05-30 12:13:26

#### HDU-2017"百度之星"程序设计大赛-复赛-1003-Pokémon GO

2017-08-18 16:47:38

#### 百度之星2014-2016资格赛试题及解答

2017-07-05 11:34:01

#### 2017百度之星初赛第一场题解

2017-08-12 16:51:25

#### 【TEST】2017百度之星程序设计大赛 - 复赛

2017-09-02 10:14:25

#### HDU 5714 拍照（百度之星复赛）【宝宝的第一个爆0场】

2016-06-10 14:28:11

#### 2016百度之星复赛 1003 拍照 扫描线

2016-05-29 17:22:04

#### HDU1548-A strange lift-最短路(Dijkstra模板题)

2015-08-29 17:02:28