Pinball Game 3D [HDU - 4742]

时间:2022-07-05 21:47:07

B - Pinball Game 3D HDU - 4742

多组数据(3)

如果 一个小球\((x,y,z)\)能弹向另一个小球\((x2,y2,z2)\),需要满足\(x\leq x2, y\leq y2, z\leq z2\),且没有相同的坐标

现在给出\(N\)个小球的坐标, 求最多能经过几个小球, 且最大的答案有多少种方案?

\(N <= 10^5, 0 <= x, y, z <= 2^{30}\)

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.

题解

同第一题, 点还不重复, 树状数组维护的信息小改改就好了, 同时维护前缀权值最大的点,以及他的个数

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;
typedef long long LL;
typedef pair<int, long long> PLI;
#define mkpr make_pair
#define fi first
#define se second
const int MAXN = 1e5 + 10;
const LL INF  = 2147483647;
const LL MOD = 1 << 30;

inline int in()
{
    int x = 0, flag = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') flag = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * flag;
}

int n, m;
LL f[MAXN], g[MAXN];

struct Two
{
    int val, cnt;
};
struct Fenwick
{
    int va[MAXN * 3];
    LL cn[MAXN * 3];
    void dec(int pos)
        {
             for (int i = pos; i <= 100000; i += (i & (-i)))
                 va[i] = cn[i] = 0;
        }
    void upd(int pos, int v, LL c)
        {
            c %= MOD;
            for (int i = pos; i <= 100000; i += (i & (-i)))
            {
                if (va[i] == v) (cn[i] += c) %= MOD;
                else if (va[i] < v) va[i] = v, cn[i] = c;
            }
        }
    PLI qry(int x)
        {
            int v = -1; LL c = 0;
            for (int i = x; i > 0; i &= (i - 1))
            {
                if (va[i] == v) (c += cn[i]) %= MOD;
                else if (va[i] > v) v = va[i], c = cn[i];
            }
            return mkpr(v, c);
        }
} T;

struct Node
{
    int x, y, z, id;
    bool operator < (const Node & b) const
        {
            return (x == b.x) ? ((y == b.y) ? z < b.z : y < b.y) : (x < b.x);
        }
} a[MAXN], b[MAXN];
void solve(int l, int r)
{
    if (l >= r) return ;
    int mid = (l + r) >> 1;
    solve(l, mid); 
    for (int i = l; i <= r; i ++) b[i] = a[i];
    sort(b + l, b + r + 1);
    for (int i = l; i <= r; i ++)
    {
        if (b[i].id <= mid) T.upd(b[i].z, f[b[i].id], g[b[i].id]);
        else
        {
            PLI res = T.qry(b[i].z);
            if (res.fi + 1 == f[b[i].id]) (g[b[i].id] += res.se) %= MOD;
            else if (res.fi + 1 > f[b[i].id]) f[b[i].id] = res.fi + 1, g[b[i].id] = res.se;
        }
    }
    for (int i = l; i <= mid; i ++) T.dec(a[i].z);
    solve(mid + 1, r);
}

map <LL, int> Map;
LL uni[MAXN * 3];
void prework()
{
    Map.clear();
    sort(uni + 1, uni + n + 1);
    int cnt = 0;
    cnt = unique(uni + 1, uni + n + 1) - uni - 1;
    for (int i = 1; i <= cnt; i ++) Map[uni[i]] = i;
    for (int i = 1; i <= n; i ++) a[i].z = Map[a[i].z];
}

int main()
{
    int test = in();
    while (test --)
    {
        memset(a, 0, sizeof a);
        memset(f, 0, sizeof f);
        memset(g, 0, sizeof g);
        n = in();
        for (int i = 1; i <= n; i ++)
        {
            f[i] = g[i] = 1;
            a[i] = (Node) { in(), in(), in(), 0 };
            uni[i] = a[i].z;
        }
        prework();
        sort(a + 1, a + n + 1);
        for (int i = 1; i <= n; i ++) a[i].x = 0, a[i].id = i;
        solve(1, n);
        int v = 0; LL c = 0;
        for (int i = 1; i <= n; i ++)
            if (f[i] > v) v = f[i], c = g[i];
            else if (f[i] == v) (c += g[i]) %= MOD;
        printf("%d %lld\n", v, c);
    }
    return 0;
}
/*
 */