做了一道水题,把bzoj1503用Splay重新写了一下。

 #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define drep(i, a, b) for (int i = a; i >= b; i--)
#define mp make_pair
#define pb push_back
#define clr(x) memset(x, 0, sizeof(x))
#define xx first
#define yy second
using namespace std;
typedef long long i64;
typedef pair<int, int> pii;
const int inf = ~0U >> ;
const i64 INF = ~0ULL >> ;
//*************************** struct node {
node *pre, *s[];
int key, size, mul;
node() { pre = s[] = s[] = ; size = mul = ; }
node(int _key) :key(_key) { pre = s[] = s[] = ; size = mul = ; }
bool getlr() { return pre->s[] == this; }
node *link(int w, node *p) { s[w] = p; if (p) p->pre = this; return this; }
void update() { size = mul + (s[] ? s[]->size : ) + (s[] ? s[]->size : ); }
} *root;
void rot(node* p) {
node *q = p->pre->pre;
p->getlr() ? p->link(, p->pre->link(, p->s[])) : p->link(, p->pre->link(, p->s[]));
p->pre->update();
if (q) q->link(q->s[] == p->pre, p);
else { p->pre = ; root = p; }
}
void splay(node *p, node *tar) {
while (p->pre != tar && p->pre->pre != tar)
p->getlr() == p->pre->getlr() ? (rot(p->pre), rot(p)) : (rot(p), rot(p));
if (p->pre) rot(p);
p->update();
}
void insrt(int k) {
node *p = root, *q = NULL;
while (p) {
q = p;
if (k > p->key) p = p->s[];
else if (k < p->key) p = p->s[];
else break;
}
if (!p) {p = new node(k);
if (!q) { root = p; return; }
q->link(q->key < k, p); q->update(); splay(p, );
}
else { p->mul++; splay(p, ); }
}
node *findkth(int x) {
node *p = root;
node *t;
while () {
int w = (p->s[] ? p->s[]->size : );
if (x <= w) t = p->s[];
else if (x > w + p->mul) { x -= w + p->mul; t = p->s[]; }
else break;
p = t;
}
splay(p, ); return p;
} node *find(node *p, int x) {
if (p->key < x) return find(p->s[], x);
else if (p->key > x) return find(p->s[], x);
else return p;
} int main() {
int ori();
int n, m;
scanf("%d%d", &n, &m);
int tot();
char op[]; int x;
while (n--) {
scanf("%s%d", op, &x);
if (op[] == 'I') {
if (x >= m) {
ori++;
insrt(x - tot);
}
}
else if (op[] == 'A') tot += x;
else if (op[] == 'S') {
tot -= x;
insrt(m - tot - );
splay(find(root, m - tot - ), );
root = root->s[];
if (root) root->pre = ;
}
else if (op[] == 'F') {
if (!root || x > root->size) puts("-1");
else printf("%d\n", findkth(root->size - x + )->key + tot);
}
}
printf("%d\n", ori - (root ? root->size : ));
return ;
}

Splay初步【bzoj1503】的更多相关文章

  1. BZOJ1503 [NOI2004]郁闷的出纳员 splay

    原文链接http://www.cnblogs.com/zhouzhendong/p/8086240.html 题目传送门 - BZOJ1503 题意概括 如果某一个员工的工资低于了min,那么,他会立 ...

  2. 【题解】 bzoj1503: [NOI2004]郁闷的出纳员 (Splay)

    bzoj1503,懒得复制,戳我戳我 Solution: 我知不知道我是那根筋抽了突然来做splay,调了起码\(3h+\),到第二天才改出来(我好菜啊),当做训练调错吧 一个裸的splay,没啥好说 ...

  3. 【BZOJ1503】 [NOI2004]郁闷的出纳员 splay

    splay模板题,都快把我做忧郁了. 由于自己调两个坑点. 1.删除时及时updata 2.Kth 考虑k满足该点的条件即r->ch[1]->size+1<=k && ...

  4. Splay的初步学习

    具体是啥,qwq 有时间再补吧,贴一下代码: #include<iostream> #include<cstdio> #include<cstring> #incl ...

  5. bzoj1503 Splay 维护名次数,支持删除

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1503 题解: 维护一颗Splay和一个外部变量,树中每个节点表示一个人,节点权值a + 外部变 ...

  6. bzoj1503[NOI2004]郁闷的出纳员——Splay

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1503 好奇怪呀!为什么而TLE? 各种修改终于卡时过了.可是大家比我快多了呀?难道是因为自己 ...

  7. bzoj1503 郁闷的出纳员 splay版

    自己yy的写法 可能有点奇怪吧 详情看代码 还是蛮短的 #include<cstdio> #include<cstring> #include<algorithm> ...

  8. [BZOJ1503]郁闷的出纳员(Splay)

    Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常 ...

  9. BZOJ1503: [NOI2004]郁闷的出纳员(Splay)

    Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的 工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经 ...

随机推荐

  1. js遍历table 和 jquery 遍历table

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  2. js date相关学习!

    var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份(4位,1970-???? ...

  3. HTTP代理浅说

    简单的说HTTP代理就是处于HTTP客户端和服务器端之间,中转消息的中间人. 一种代理是代客户端去请求服务器,叫做Forward Proxy正向代理:另一种是代理真正的服务器来接收用户请求,叫做Rev ...

  4. 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp

    http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...

  5. script 两则

    script1: PATH=/usr/local/bin:/usr/bin:$PATH:. . $HOME/utility/macro/macro.env OVO_DIR=/tmp LOGFILE=$ ...

  6. gen_grant_exec.sql

    set echo off feedback off verify off pagesize 0 linesize 120 define v_grantee                 = & ...

  7. input file图片上传预览

    两种方法,方法一: js代码: //头像上传预览 $("#up").change(function() { var $file = $(this); var fileObj = $ ...

  8. HDU 5692 (DFS序+线段树)

    DFS获得从0到每一个顶点的距离,同时获得L和R数组.两数组为遍历时从i进入再从i出来的序列. #pragma comment(linker, "/STACK:1024000000,1024 ...

  9. C#+QI的例子

    COM中,和我们打交道的是接口,也就是说类对我们是隐形的,那么我们要做开发,要使用这些功能,我们只能通过接口,通过接口暴露出来的方法,COM是一种服务器端/客户端架构,服务器端定义了操作的法,客户端通 ...

  10. ExtJS如何取得GridPanel当前选择行数据对象 - nuccch的专栏 - 博客频道 - CSDN.NET

    body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...