BZOJ5509: [Tjoi2019]甲苯先生的滚榜
题解
开n个平衡树对每个AC数维护罚时,然后不同AC数用树状数组维护即可。
其实挺好写的...就是评测的时候评的巨久...
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000010;
int T, n, m, cnt[N], tim[N];
namespace Rand {
typedef unsigned int ui;
ui seed;
ui randNum(ui& seed, ui last, const ui m) {
seed = seed * 17 + last;
return seed % m + 1;
}
}
namespace fhqtreap {
int root[N], tot;
struct treap {int lc, rc, val, rnd, siz;} t[N<<2];
void clear() {memset(root, 0, sizeof(root)); tot = 0;}
void up(int rt) {t[rt].siz = t[t[rt].lc].siz + t[t[rt].rc].siz + 1;}
int build(int val) {
t[++tot] = (treap) {0, 0, val, rand()<<15|rand(), 1};
return tot;
}
void split(int rt, int &l, int &r, int c) {
if(!rt) l = r = 0;
else if(t[rt].val <= c) split(t[l = rt].rc, t[rt].rc, r, c), up(rt);
else split(t[r = rt].lc, l, t[rt].lc, c), up(rt);
}
void merge(int &rt, int l, int r) {
if(!l || !r) rt = l + r;
else if(t[l].rnd < t[r].rnd) rt = l, merge(t[rt].rc, t[rt].rc, r), up(rt);
else rt = r, merge(t[rt].lc, l, t[rt].lc), up(rt);
}
void insert(int id, int val) {
int x, y, z = build(val);
split(root[id], x, y, val);
merge(x, x, z); merge(root[id], x, y);
}
void Del(int id, int val) {
int x, y, z;
split(root[id], x, y, val);
split(x, x, z, val - 1);
merge(z, t[z].lc, t[z].rc);
merge(x, x, z); merge(root[id], x, y);
}
int rnk(int rt, int val) {
if(!rt) return 0;
if(t[rt].val >= val) return rnk(t[rt].lc, val);
return rnk(t[rt].rc, val) + t[t[rt].lc].siz + 1;
}
}
namespace BIT {
int c[N];
#define lowbit(i) (i & -i)
void clear() {memset(c, 0, sizeof(c));}
void add(int x, int v) {for(int i = x; i <= n; i += lowbit(i)) c[i] += v;}
int query(int x) {int ans = 0; for(int i = x; i; i -= lowbit(i)) ans += c[i]; return ans;}
}
int main() {
int ans = 7; scanf("%d", &T); while(T--) {
fhqtreap::clear(); BIT::clear();
memset(cnt, 0, sizeof(cnt)); memset(tim, 0, sizeof(tim));
scanf("%d%d%u", &m, &n, &Rand::seed);
for(int i = 1; i <= n; ++i) {
int Ria = Rand::randNum(Rand::seed, ans, m);
int Rib = Rand::randNum(Rand::seed, ans, m);
if(cnt[Ria]) {
fhqtreap::Del(cnt[Ria], tim[Ria]);
BIT::add(cnt[Ria], -1);
}
tim[Ria] += Rib; ++cnt[Ria];
BIT::add(cnt[Ria], 1);
fhqtreap::insert(cnt[Ria], tim[Ria]);
ans = fhqtreap::rnk(fhqtreap::root[cnt[Ria]], tim[Ria]) + BIT::query(n) - BIT::query(cnt[Ria]);
printf("%d\n", ans);
}}
return 0;
}
BZOJ5509: [Tjoi2019]甲苯先生的滚榜的更多相关文章
- [TJOI2019]甲苯先生的滚榜——非旋转treap
题目链接: [TJOI2019]甲苯先生的滚榜 要求维护一个二维权值的集合并支持单点修改,用平衡树维护即可. 因为$n\le 10^6$但$m\le 10^5$,所以最多只有$10^5$个人被操作. ...
- 洛谷P5338 [TJOI2019]甲苯先生的滚榜
原题链接洛谷P5338 [TJOI2019]甲苯先生的滚榜 题目描述 甲苯先生在制作一个online judge,他发现做比赛的人们很关心自己的排名(显而易见),在acm赛制的比赛中,如果通过题目数量 ...
- 【题解】Luogu P5338 [TJOI2019]甲苯先生的滚榜
原题传送门 这题明显可以平衡树直接大力整,所以我要说一下线段树+树状数组的做法 实际线段树+树状数组的做法也很暴力 我们先用树状数组维护每个ac数量有多少个队伍.这样就能快速求出有多少队伍ac数比现在 ...
- luogu P5338 [TJOI2019]甲苯先生的滚榜
传送门 首先,排名系统,一看就知道是原题,可以上平衡树来维护 然后考虑一种比较朴素的想法,因为我们要知道排名在一个人前面的人数,也就是AC数比他多的人数+AC数一样并且罚时少的人数,所以考虑维护那两个 ...
- LG5338/BZOJ5509/LOJ3105 「TJOI2019」甲苯先生的滚榜 Treap
问题描述 LG5338 LOJ3105 BZOJ5509 题解 建立一棵\(\mathrm{Treap}\),把原来的\(val\)换成两个值\(ac,tim\) 原来的比较\(val_a<va ...
- 「TJOI2019」甲苯先生的滚榜
题目链接 问题分析 参照数据范围,我们需要一个能够在\(O(n\log n)\)复杂度内维护有序数列的数据结构.那么平衡树是很好的选择.参考程序中使用带旋Treap. 参考程序 #pragma GCC ...
- [TJOI2019]甲苯先生和大中锋的字符串——后缀自动机+差分
题目链接: [TJOI2019]甲苯先生和大中锋的字符串 对原串建后缀自动机并维护$parent$树上每个点的子树大小,显然子树大小为$k$的节点所代表的子串出现过$k$次,那么我们需要将$[len[ ...
- [TJOI2019]甲苯先生的字符串——矩阵乘法+递推
题目链接: [TJOI2019]甲苯先生的字符串 我们用一个$26*26$的$01$矩阵记录任意两个字符是否能相邻. 设$f[i][j]$表示处理完前$i$个字符,第$i$个字符为$j$的方案数. 可 ...
- 洛谷P5341 [TJOI2019]甲苯先生和大中锋的字符串
原题链接P5341 [TJOI2019]甲苯先生和大中锋的字符串 题目描述 大中锋有一个长度为 n 的字符串,他只知道其中的一个子串是祖上传下来的宝藏的密码.但是由于字符串很长,大中锋很难将这些子串一 ...
随机推荐
- 图、流程图、ER图怎么画及常见画图工具(流程图文章汇总)
流程图基本符号 首先要记住图中1.2.3.4.6这几种符号. 图片摘自网络 流程图基本概念及入门 简易流程图 流程图简介(基本符号与绘制工具) 你可能学了假流程图,三步教会你绘制大厂流程图 使用流程图 ...
- gunicorn 参数
gunicorn -w 4 -b 0.0.0.0:8080 yourpyfilename:app --log-level DEBUG --timeout 60gunicorn的命令对应参数含义如下: ...
- 【数据结构】【计算机视觉】并查集(disjoint set)结构介绍
1.简述 在实现多图像无序输入的拼接中,我们先使用surf算法对任意两幅图像进行特征点匹配,每对图像的匹配都有一个置信度confidence参数,来衡量两幅图匹配的可信度,当confidence> ...
- just the check 买单
今日焦点 Just the check 买单吧 split it 平分 leave a tip 留小费 词汇实践 hey. Can I get you anything else today? 您好. ...
- docker 学习操作记录 4
记录3 [BEGIN] // :: Connecting to ... Connection established. To escape to local shell, press Ctrl+Alt ...
- TeamViewer 一款远程控制软件
TeamViewer 一款远程控制软件,可以在任何防火圈和Nat代理的后台用于远程控制的应用程序. 主要功能:桌面共享和文件传输. 使用前提:两台计算机上同时运行TeamViewer, 使用方法:如果 ...
- tkinter添加背景音乐
一.问题利用tkinter来写一个游戏,添加一个背景音乐提高可玩性. 二.解决1.安装pygame首先是利用pygame的一个播放流:[pip install pygame]来完成pygame的安装. ...
- Linux常用命令wc
wc名字来源: wc -- word, line, character, and byte count The wc utility displays the number of lines, wor ...
- C#项目 App.config 配置文件不同使用环境配置
问题 部署项目时,常常需要根据不同的环境使用不同的配置文件.例如,在部署网站时可能希望禁用调试选项,并更改连接字符串以使其指向不同的数据库.在创建 Web 项目时,Visual Studio 自动生成 ...
- pickle导入变量AttributeError的解决方案
问题描述: AttributeError: 'module' object has no attribute ‘attr1’ 解决方案: # 找到报错的文件a.py from a import att ...