[TJOI2019]甲苯先生的滚榜——非旋转treap
题目链接:
要求维护一个二维权值的集合并支持单点修改,用平衡树维护即可。
因为$n\le 10^6$但$m\le 10^5$,所以最多只有$10^5$个人被操作。
记录每个人的二维权值,只维护被操作过的人权值的平衡树即可。
如果一开始将$10^6$个人都建出来会$TLE$。
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef unsigned int ui;
int ls[100010];
int rs[100010];
int r[100010];
int v[100010];
int t[100010];
int size[100010];
int cnt;
int m,T;
ui seed;
int x,y;
int a,b,c;
ui last=7;
ui n;
int ac[1000010];
int tim[1000010];
int root;
ui randNum(ui& seed,ui last,const ui m)
{
seed=seed*17+last;
return seed%m+1;
}
inline void init()
{
cnt=root=0;
memset(ac,0,sizeof(ac));
memset(tim,0,sizeof(tim));
}
inline int build(int val)
{
int rt=++cnt;
r[rt]=rand();
v[rt]=1;
t[rt]=val;
size[rt]=1;
ls[rt]=rs[rt]=0;
return rt;
}
inline void pushup(int rt)
{
size[rt]=size[ls[rt]]+size[rs[rt]]+1;
}
inline int merge(int x,int y)
{
if(!x||!y)
{
return x+y;
}
if(r[x]<r[y])
{
rs[x]=merge(rs[x],y);
pushup(x);
return x;
}
else
{
ls[y]=merge(x,ls[y]);
pushup(y);
return y;
}
}
inline void split(int rt,int &x,int &y,int ac,int tim)
{
if(!rt)
{
x=y=0;
return ;
}
if(v[rt]<ac||(v[rt]==ac&&t[rt]>=tim))
{
y=rt;
split(ls[rt],x,ls[y],ac,tim);
pushup(y);
}
else
{
x=rt;
split(rs[rt],rs[x],y,ac,tim);
pushup(x);
}
}
inline void split2(int rt,int &x,int &y,int k)
{
if(!rt)
{
x=y=0;
return ;
}
if(size[ls[rt]]>=k)
{
y=rt;
split2(ls[rt],x,ls[y],k);
pushup(y);
}
else
{
x=rt;
split2(rs[rt],rs[x],y,k-size[ls[rt]]-1);
pushup(x);
}
}
inline void solve()
{
scanf("%u%d%u",&n,&m,&seed);
for(int i=1;i<=m;i++)
{
x=randNum(seed,last,n);
y=randNum(seed,last,n);
if(!ac[x])
{
ac[x]++;
tim[x]+=y;
int now=build(tim[x]);
split(root,a,b,ac[x],tim[x]);
root=merge(a,merge(now,b));
}
else
{
split(root,a,b,ac[x],tim[x]);
split2(b,b,c,1);
v[b]++;
t[b]+=y;
root=merge(a,c);
split(root,a,c,v[b],t[b]);
root=merge(merge(a,b),c);
ac[x]++;
tim[x]+=y;
}
split(root,a,b,ac[x],tim[x]);
last=size[a];
printf("%d\n",last);
root=merge(a,b);
}
}
int main()
{
scanf("%d",&T);
while(T--)
{
init();
solve();
}
}
[TJOI2019]甲苯先生的滚榜——非旋转treap的更多相关文章
- 洛谷P5338 [TJOI2019]甲苯先生的滚榜
原题链接洛谷P5338 [TJOI2019]甲苯先生的滚榜 题目描述 甲苯先生在制作一个online judge,他发现做比赛的人们很关心自己的排名(显而易见),在acm赛制的比赛中,如果通过题目数量 ...
- BZOJ5509: [Tjoi2019]甲苯先生的滚榜
题解 开n个平衡树对每个AC数维护罚时,然后不同AC数用树状数组维护即可. 其实挺好写的...就是评测的时候评的巨久... #include <bits/stdc++.h> using n ...
- 【题解】Luogu P5338 [TJOI2019]甲苯先生的滚榜
原题传送门 这题明显可以平衡树直接大力整,所以我要说一下线段树+树状数组的做法 实际线段树+树状数组的做法也很暴力 我们先用树状数组维护每个ac数量有多少个队伍.这样就能快速求出有多少队伍ac数比现在 ...
- luogu P5338 [TJOI2019]甲苯先生的滚榜
传送门 首先,排名系统,一看就知道是原题,可以上平衡树来维护 然后考虑一种比较朴素的想法,因为我们要知道排名在一个人前面的人数,也就是AC数比他多的人数+AC数一样并且罚时少的人数,所以考虑维护那两个 ...
- [bzoj3173]最长上升子序列_非旋转Treap
最长上升子序列 bzoj-3173 题目大意:有1-n,n个数,第i次操作是将i加入到原有序列中制定的位置,后查询当前序列中最长上升子序列长度. 注释:1<=n<=10,000,开始序列为 ...
- 关于非旋转treap的学习
非旋转treap的操作基于split和merge操作,其余操作和普通平衡树一样,复杂度保证方式与旋转treap差不多,都是基于一个随机的参数,这样构出的树树高为\(logn\) split 作用:将原 ...
- [Codeforces702F]T-Shirts——非旋转treap+贪心
题目链接: Codeforces702F 题目大意:有$n$种T恤,每种有一个价格$c_{i}$和品质$q_{i}$且每种数量无限.现在有$m$个人,第$i$个人有$v_{i}$元,每人每次会买他能买 ...
- BZOJ5063旅游——非旋转treap
题目描述 小奇成功打开了大科学家的电脑. 大科学家打算前往n处景点旅游,他用一个序列来维护它们之间的顺序.初 始时,序列为1,2,...,n. 接着,大科学家进行m次操作来打乱顺序.每次操作有6步: ...
- BZOJ3223文艺平衡树——非旋转treap
此为平衡树系列第二道:文艺平衡树您需要写一种数据结构,来维护一个有序数列,其中需要提供以下操作: 翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2 3 4 1 ...
随机推荐
- restTemplate源码解析(目录)
restTemplate是spring实现的,基于restful风格的http请求模板.使用restTemplate可以简化请求操作的复杂性,同时规范了代码风格.本系列文章,将根据以下目录顺序,从源码 ...
- 通过 Java 压缩文件,打包一个 tar.gz 采集器包
一.如何通过 Java 打包文件 1.1 添加 Maven 依赖 <dependency> <groupId>org.apache.commons</groupId> ...
- sql 防注入(更新问题)
一下这条语句虽然不会是数据表中的数据发生变化,但是会对数据库主从造成影响 update `article` where `article_id` = '40&n974742=v995656' ...
- Java虚拟机(五):JVM 类加载机制
一.JVM 类加载机制 JVM 类加载机制分为五个部分:加载,验证,准备,解析,初始化,下面我们就分别来看一下这五个过程. 1. 加载: 加载是类加载过程中的第一个阶段,这个阶段会在内存中生成一个代表 ...
- selenium按钮
学习使用selenium第一个坑,按钮type,submit,button driver.findElement(By.id("su")).submit() driver.find ...
- Python requests.post嵌套多层json参数调用接口
#coding:utf-8 import requests,json #第一行注解的#coding:utf-8表示可以支持中文,不然代码里面有中文会报错 url = "http://xxx& ...
- 初始化springbean
public class SMSMessageHandler implements InitializingBean { @Overridepublic void afterPropertiesSet ...
- Django modle基础样版
定义一个基类模版, from django.db import models class ModelBase(models.Model): """ "" ...
- 读取xml时,报错:xml.etree.ElementTree.ParseError: no element found: line 20, column 9
读取xml时,出现报错:xml.etree.ElementTree.ParseError: no element found: line 20, column 9 原因是xml文件格式有问题,可以检查 ...
- P1417 烹调方案[背包]
题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船飞到一半,gw发现了一个很严重的问题:肚子饿了~ gw还是会做饭的,于是拿出了储藏的 ...