HDU 4742 Pinball Game 3D (cdq分治)

HDU4742

经典题,可以用树套树,也可以用cdq分治,还是cdq分治写起来比较方便!

Pinball Game 3D

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 630 Accepted Submission(s): 254

Problem Description

RD is a smart boy and excel in pinball game. However, playing common 2D pinball game for a great number of times results in accumulating tedium.Recently, RD has found a new type of pinball game, a 3D pinball game. The 3D pinball game space can be regarded as a three dimensional coordinate system containing N balls. A ball can be considered as a point. At the beginning, RD made a shot and hit a ball. The ball hit by RD will move and may hit another ball and the “another ball” may move and hit another another ball, etc. But once a ball hit another ball, it will disappear. RD is skilled in this kind of game, so he is able to control every ball’s moving direction. But there is a limitation: if ball A’s coordinate is (x1,y1,z1) and ball B’s coordinate is (x2,y2,z2), then A can hit B only if x1 <= x2 and y1 <= y2 and z1 <= z2. Now, you should help RD to calculate the maximum number of balls that can be hit and the number of different shooting schemes that can achieve that number. Two schemes are different if the sets of hit balls are not the same. The order doesn’t matter.

Input

The first line contains one integer T indicating the number of cases. In each case, the first line contains one integer N indicating the number of balls. The next N lines each contains three non-negative integer (x, y, z), indicating the coordinate of a ball. The data satisfies T <= 3, N <= 105, 0 <= x, y, z <= 230, no two balls have the same coordinate in one case.

Output

Print two integers for each case in a line, indicating the maximum number of balls that can be hit and the number of different shooting schemes. As the number of schemes can be quite large, you should output this number mod 230.

Sample Input

2 3 2 0 0 0 1 0 0 1 1 5 3 0 0 0 1 0 0 0 1 0 2 2 3 3 3

Sample Output

2 1 3 2

Hint

In the first case, RD can shoot the second ball at first and hit the third ball indirectly. In the second case, RD can shoot the second or the third ball initially and hit the fourth ball as well as the fifth ball. Two schemes are both the best.

Source

2013 ACM/ICPC Asia Regional Hangzhou Online

就是三维的LIS。 按照x排序可以减少一维,然后使用cdq分治的方法,用左边的去更新右边的,按照y的顺序加入。   要对z进行离散化。  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/* ***************

Author :kuangbin

Created Time :2014/9/4 21:53:53

File Name :E:\2014ACM\专题学习\CDQ分治\HDU4742.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 namespace std;

const int MAXN = 100010;

const int MOD = (1<<30);

void update(pair<int,int>&p1,pair<int,int>p2){

if(p1.first < p2.first)p1 = p2;

else if(p1.first == p2.first){

p1.second += p2.second;

if(p1.second >= MOD)p1.second -= MOD;

}

}

pair<int,int>dp[MAXN];

pair<int,int>c[MAXN];

int n;

int lowbit(int x){

return x&(-x);

}

void add(int i,pair<int,int>val){

while(i <= n){

update(c[i],val);

i += lowbit(i);

}

}

pair<int,int> sum(int i){

pair<int,int>res = make_pair(0,0);

while(i > 0){

update(res,c[i]);

i -= lowbit(i);

}

return res;

}

void CLR(int i){

while(i <= n){

c[i] = make_pair(0,0);

i += lowbit(i);

}

}

struct Point{

int x,y,z;

int id;

void input(){

scanf("%d%d%d",&x,&y,&z);

}

}p[MAXN];

bool cmpx(Point a,Point b){

if(a.x != b.x)return a.x < b.x;

else if(a.y != b.y)return a.y < b.y;

else return a.z < b.z;

}

bool cmpy(Point a,Point b){

if(a.y != b.y)return a.y < b.y;

else return a.z < b.z;

}

int zz[MAXN];

void solve(int l,int r){

if(l == r)return;

int mid = (l+r)/2;

solve(l,mid);

sort(p+l,p+mid+1,cmpy);

sort(p+mid+1,p+r+1,cmpy);

int j = l;

for(int i = mid+1;i <= r;i++){

while(j <= mid && p[j].y <= p[i].y)

{

add(p[j].z,dp[p[j].id]);

j++;

}

pair<int,int> res = sum(p[i].z);

res.first++;

update(dp[p[i].id],res);

}

for(int i = l;i <= mid;i++)CLR(p[i].z);

sort(p+mid+1,p+r+1,cmpx);

solve(mid+1,r);

}

int main()

{

//freopen("in.txt","r",stdin);

//freopen("out.txt","w",stdout);

int T;

scanf("%d",&T);

while(T--){

scanf("%d",&n);

int cnt = 0;

for(int i = 1;i <= n;i++){

p[i].input();

zz[++cnt] = p[i].z;

}

sort(zz+1,zz+cnt+1);

cnt = unique(zz+1,zz+cnt+1)-zz-1;

for(int i = 1;i <= n;i++)

p[i].z = lower_bound(zz+1,zz+cnt+1,p[i].z)-zz;

sort(p+1,p+n+1,cmpx);

for(int i = 1;i <= n;i++)

p[i].id = i;

for(int i = 1;i <= n;i++){

c[i] = make_pair(0,0);

dp[i] = make_pair(1,1);

}

solve(1,n);

pair<int,int>ans = make_pair(0,0);

for(int i = 1;i <= n;i++)

update(ans,dp[i]);

printf("%d %d\n",ans.first,ans.second);

}

return 0;

}
------ 本文结束------
  • 本文作者: kuangbin
  • 本文链接: 368.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
0%