树套树【bzoj3262】陌上花开
/*
【bzoj3262】陌上花开
Description
Input
Output
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#define M 5000005
using namespace std;
struct shu
{
int x,y,z;
}a[100005];
int n,m,sum[100005],ans[100005],sz,root[200005],w[M],v[M],sz1[M],lr[M],rr[M],rou[M];
int tmp;
bool cmp(shu a1,shu a2)
{
if(a1.x==a2.x&&a1.y==a2.y)
return a1.z<a2.z;
if(a1.x==a2.x)
return a1.y<a2.y;
return a1.x<a2.x;
}
void update(int a1)
{
sz1[a1]=sz1[lr[a1]]+sz1[rr[a1]]+w[a1];
}
void zuo(int &a1)
{
int t=lr[a1];
lr[a1]=rr[t];
rr[t]=a1;
update(a1);
update(t);
a1=t;
}
void you(int &a1)
{
int t=rr[a1];
rr[a1]=lr[t];
lr[t]=a1;
update(a1);
update(t);
a1=t;
}
void jiaa(int &a1,int a2)
{
if(a1==0)
{
sz++;
a1=sz;
v[a1]=a2;
sz1[a1]=1;
w[a1]=1;
rou[a1]=rand();
return;
}
sz1[a1]++;
if(v[a1]==a2)
{
w[a1]++;
return;
}
if(v[a1]>a2)
{
jiaa(lr[a1],a2);
if(rou[lr[a1]]<rou[a1])
zuo(a1);
}
else
{
jiaa(rr[a1],a2);
if(rou[rr[a1]]<rou[a1])
you(a1);
}
}
void jia(int a1,int a2)
{
for(;a1<=m;a1+=(a1&(-a1)))
jiaa(root[a1],a2);
}
void askk(int a1,int a2)
{
if(a1==0)
return;
if(v[a1]==a2)
{
tmp+=w[a1]+sz1[lr[a1]];
return;
}
if(v[a1]>a2)
askk(lr[a1],a2);
else
{
tmp+=w[a1]+sz1[lr[a1]];
askk(rr[a1],a2);
}
return;
}
void ask(int a1,int a2)
{
for(;a1;a1-=(a1&(-a1)))
askk(root[a1],a2);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)
{
if(a[i].y==a[i+1].y&&a[i].z==a[i+1].z&&a[i].x==a[i+1].x&&i!=n)
sum[i+1]+=sum[i]+1;
else
{
tmp=0;
ask(a[i].y,a[i].z);
ans[tmp]+=sum[i]+1;
}
jia(a[i].y,a[i].z);
}
for(int i=0;i<n;i++)
printf("%d\n",ans[i]);
return 0;
}
树套树【bzoj3262】陌上花开的更多相关文章
- 【BZOJ3262】陌上花开(树套树)
[BZOJ3262]陌上花开(树套树) 题面 对于权限题,我这种苦逼肯定是从别的OJ上搞的对不对??? CJOJ 洛谷 Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味 ...
- bzoj3262: 陌上花开(树套树)
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- [Bzoj3262]陌上花开(CDQ分治&&树状数组||树套树)
题目链接 题目就是赤裸裸的三维偏序,所以用CDQ+树状数组可以比较轻松的解决,但是还是树套树好想QAQ CDQ+树状数组 #include<bits/stdc++.h> using nam ...
- BZOJ 3110: [Zjoi2013]K大数查询 [树套树]
3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6050 Solved: 2007[Submit][Sta ...
- BZOJ4170 极光(CDQ分治 或 树套树)
传送门 BZOJ上的题目没有题面-- [样例输入] 3 5 2 4 3 Query 2 2 Modify 1 3 Query 2 2 Modify 1 2 Query 1 1 [样例输出] 2 3 3 ...
- bzoj3295: [Cqoi2011]动态逆序对(树套树)
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- BZOJ 3110 k大数查询 & 树套树
题意: 有n个位置,每个位置可以看做一个集合,现在要求你实现一个数据结构支持以下功能: 1:在a-b的集合中插入一个数 2:询问a-b集合中所有元素的第k大. SOL: 调得火大! 李建说数据结构题能 ...
- BZOJ 3110 树套树 && 永久化标记
感觉树套树是个非常高深的数据结构.从来没写过 #include <iostream> #include <cstdio> #include <algorithm> ...
- 【BZOJ】1901: Zju2112 Dynamic Rankings(区间第k小+树套树)
http://www.lydsy.com/JudgeOnline/problem.php?id=1901 这题调了我相当长的时间,1wa1a,我是第一次写树套树,这个是树状数组套splay,在每个区间 ...
随机推荐
- 【Leetcode】746. Min Cost Climbing Stairs
题目地址: https://leetcode.com/problems/min-cost-climbing-stairs/description/ 解题思路: 官方给出的做法是倒着来,其实正着来也可以 ...
- WebSocket 的应用
后面用到了再来做整理 链接地址:https://www.cnblogs.com/zhaof/p/9833614.html
- 【转】HTTP响应状态码参考簿
HTTP响应状态码参考簿 http状态返回代码 1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态代码. http状态返回代码 代码 说明100 (继续) 请求者应当继续提出请求. ...
- PHP变量的范围
1.局部变量 function test(){ $a=1;//局部变量$a,尽在这个函数内部有效 } echo $a; 2.全局变量 $i=10;//全局变量(外部变量) define('MY_NAM ...
- web开发常见的鉴权方式
结合网上找的资料整理了一下,以下是web开发中常见的鉴权方法: 预备:一些基本的知识 RBAC(Role-Based Access Control)基于角色的权限访问控制(参考下面①的连接) l ...
- HDU 4862 Jump 任意起点最大权K链不相交覆盖
你可以从任意起点开始起跳最多K次 每次跳你可以选择往右或者往下跳 从(x1,y1)跳到(x2,y2) 消耗的能量是曼哈顿距离-1 但是如果每次跳的起点和终点格子里的数字是相同的为X的话你会得到X能量 ...
- .Net系列 Transaction 事务
Transactions 事务(Transaction),一般是指要做的或所做的事情.在计算机术语中是指访问并可能更新数据库中各种数据项的一个程序执行单元(unit).在计算机术语中,事务通常就是指数 ...
- ASP.NET MVC 入门5、View与ViewData
View建立时有MVC View Page 和 MVC View Content Page两种类型, 前者为标准View, 后者为可继承Master母版页的View. Asp.Net MVC 默认使用 ...
- numpy模块的基本使用
numpy(Numerical Python)提供了python对多维数组对象的支持:ndarray,具有矢量运算能力,快速.节省空间.numpy支持高级大量的维度数组与矩阵运算,此外也针对数组运算提 ...
- WebStorm 简单搭建NodeJs服务
开始使用 WebStorm 搭建( WebStorm 请自行安装...... ) 在 项目 根目录 新建个 app.js 开始 编写 app,js // 引入 HTTP 模块 const http = ...