【BZOJ3262】陌上花开(树套树)

126 篇文章 3 订阅
59 篇文章 0 订阅

题面

对于权限题,我这种苦逼肯定是从别的OJ上搞的对不对???
CJOJ
洛谷

Description

有n朵花,每朵花有三个属性:花形(s)、颜色(c)、气味(m),又三个整数表示。现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量。
定义一朵花A比另一朵花B要美丽,当且仅当Sa>=Sb,Ca>=Cb,Ma>=Mb。显然,两朵花可能有同样的属性。需要统计出评出每个等级的花的数量。

Input

第一行为N,K (1 <= N <= 100,000, 1 <= K <= 200,000 ), 分别表示花的数量和最大属性值。
以下N行,每行三个整数si, ci, mi (1 <= si, ci, mi <= K),表示第i朵花的属性

Output

包含N行,分别表示评级为0…N-1的每级花的数量。

Sample Input

10 3

3 3 3

2 3 3

2 3 1

3 1 1

3 1 2

1 3 1

1 1 2

1 2 2

1 3 2

1 2 1

Sample Output

3
1
3
0
1
0
1
0
0
1

Hint

数据范围:
1 <= N <= 100,000, 1 <= K <= 200,000

题解

然而我太菜了,不会CDQ分治

智商不够数据结构来补 ——– 菊开
所以,当然就是数据结构来补智商

很显然的,傻逼都想得到的第一维当然是sort呀
第二维,显然就是要找前面的比他小的个数
那要维护区间,要搞值域,当然是树状数组或者线段树了
第三维要找这段区间内比他小的点的个数,当然是平衡数了

于是,平衡树只会Splay的我就打了一个树状数组套Splay,慢的飞起
我还是太菜啦。。。。
orz球爷,成为了继就老爷后,第二个替罪羊树dalao
这题我改了好久。。。
原因是Splay在Insert之后忘记Spaly
然后就没有pushup,所以size挂了。。。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAX 100010
inline int read()
{
    register int x=0,t=1;
    register char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-'){t=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
    return x*t;
}
int ans[MAX];
struct seq
{
    int a,b,c;
}s[MAX];
int K;
inline int lowbit(int x){return x&(-x);}
struct Node
{
    int ch[2];
    int v,f,size,cnt;
}t[MAX<<5];
int root[MAX<<1];
int n,tot;
inline void pushup(int x)
{
    t[x].size=t[t[x].ch[0]].size+t[t[x].ch[1]].size+t[x].cnt;
}
void rotate(int x)
{
    int y=t[x].f,z=t[y].f;
    int k=t[y].ch[1]==x;
    t[z].ch[t[z].ch[1]==y]=x;t[x].f=z;
    t[y].ch[k]=t[x].ch[k^1];t[t[x].ch[k^1]].f=y;
    t[x].ch[k^1]=y;t[y].f=x;
    pushup(y);pushup(x);
}
void Splay(int x,int goal)
{
    while(t[x].f!=goal)
    {
        int y=t[x].f,z=t[y].f;
        if(z!=goal)
            (t[y].ch[0]==x)^(t[z].ch[0]==y)?rotate(x):rotate(y);
        rotate(x);
    }
    if(goal<=K)root[goal]=x;
}
void insert(int x,int k,int dd)
{
    int u=root[k],f=k;
    while(u&&t[u].v!=x)
        f=u,u=t[u].ch[t[u].v<x];
    if(u>K)
    {
        t[u].cnt+=dd;t[u].size+=dd;
    }
    else
    {
        u=++tot;
        if(f>K)
            t[f].ch[t[f].v<x]=u;
        t[u].f=f;t[u].v=x;t[u].size=dd;t[u].cnt=dd;
    }
    Splay(u,k);
}
int get(int x,int k)
{
    int u=root[k],re=0;
    while(u)
    {
        if(x>=t[u].v)re+=t[t[u].ch[0]].size+t[u].cnt;
        if(x==t[u].v)break;
        u=t[u].ch[t[u].v<x];
    }
    return re;
}
void Add(int x,int w,int dd)
{
    while(x<=K)
    {
        insert(w,x,dd);
        x+=lowbit(x);
    }
}
int getsum(int x,int w)
{
    int re=0;
    while(x)
    {
        re+=get(w,x);
        x-=lowbit(x);
    }
    return re;
}
inline bool operator<(seq a,seq b)
{
    if(a.a!=b.a)
        return a.a<b.a;
    if(a.b!=b.b)
        return a.b<b.b;
    return a.c<b.c;
}
inline bool operator==(seq a,seq b)
{
    return a.a==b.a&&a.b==b.b&&a.c==b.c;
}
int main()
{
    n=read();tot=K=read();
    for(int i=1;i<=n;++i)s[i].a=read(),s[i].b=read(),s[i].c=read();
    sort(&s[1],&s[n+1]);
    int ccc=0;
    for(int i=1;i<=n;++i)
    {
        ccc++;
        if(s[i]==s[i+1])continue;
        ans[getsum(s[i].b,s[i].c)+ccc-1]+=ccc;
        Add(s[i].b,s[i].c,ccc);
        ccc=0;
    }
    for(int i=0;i<n;++i)
        printf("%d\n",ans[i]);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值