(WA)BZOJ 1503: [NOI2004]郁闷的出纳员
二次联通门 : BZOJ 1503: [NOI2004]郁闷的出纳员
- /*
- BZOJ 1503: [NOI2004]郁闷的出纳员
- 考虑这样一个事实
- 无论是加或减
- 都是针对全体人员的
- 那么只需要记录一个总标记
- 直接记录对于工资的加或减
- 每次查询最低要求工资与标记的差的前驱,并旋到根处
- 那么根节点的所有左子树都是不符合要求要走人的
- 每次记录一下搞一搞, 就不用考虑splay麻烦的标记下放问题了
但是却没调出来。。。- */
- #include <cstdio>
- void read (int &now)
- {
- register char word = getchar ();
- bool temp = false;
- for (now = ; word < '' || word > ''; word = getchar ())
- if (word == '-')
- temp = true;
- for (; word >= '' && word <= ''; now = now * + word - '', word = getchar ());
- if (temp)
- now = -now;
- }
- int Min_N;
- struct S_D
- {
- S_D *child[], *father;
- int key;
- int weigth, size;
- inline void Updata ()
- {
- this->size = this->weigth;
- if (this->child[])
- this->size += this->child[]->size;
- if (this->child[])
- this->size += this->child[]->size;
- }
- S_D ()
- {
- child[] = child[] = NULL;
- size = weigth = ;
- key = ;
- father = NULL;
- }
- inline int Get_Pos ()
- {
- return this->father->child[] == this;
- }
- inline void Clear ()
- {
- this->child[] = this->child[] = father = NULL;
- }
- };
- int Answer;
- class Splay_Tree_Type
- {
- private :
- S_D *Root;
- inline void Rotate (S_D *now)
- {
- S_D *Father = now->father;
- register int pos = now->Get_Pos () ^ ;
- Father->child[pos ^ ] = now->child[pos];
- if (now->child[pos])
- now->child[pos]->father = Father;
- if ((now->father = Father->father) != NULL)
- now->father->child[now->father->child[] == Father] = now;
- Father->father = now;
- now->child[pos] = Father;
- Father->Updata ();
- now->Updata ();
- if (now->father == NULL)
- Root = now;
- }
- inline void Splay (S_D *now)
- {
- for (S_D *Father; Father = now->father; this->Rotate (now))
- if (Father->father != NULL)
- this->Rotate (now->Get_Pos () == Father->Get_Pos () ? Father : now);
- }
- S_D* Find (int x)
- {
- S_D *now = Root;
- for (; (now != NULL && now->key != x); now = now->child[x > now->key]);
- if (now == NULL)
- return now;
- Splay (now);
- return now;
- }
- void Delete_point (int x)
- {
- S_D *now = Find (x);
- if (now->weigth > )
- {
- now->weigth --;
- return ;
- }
- if (now->child[] == NULL && now->child[] == NULL)
- {
- now->Clear ();
- Root = NULL;
- return ;
- }
- S_D *res;
- if (now->child[] == NULL)
- {
- Root = now->child[];
- now->child[]->father = NULL;
- now->Clear ();
- return ;
- }
- if (now->child[] == NULL)
- {
- Root = now->child[];
- now->child[]->father = NULL;
- now->Clear ();
- return ;
- }
- S_D *Prefix = Find_Prefix (x);
- res = Root;
- Prefix->child[] = res->child[];
- res->child[]->father = Root;
- res->Clear ();
- Root->Updata ();
- }
- void Delete_tree (int x)
- {
- S_D *now = Find_Suffix (x);
- if (now == NULL)
- return ;
- Answer += now->child[]->size;
- now->child[]->father = NULL;
- now->child[] = NULL;
- now->Updata ();
- }
- S_D *Find_Suffix (int x)
- {
- this->Insert (x);
- S_D *now = Root;
- if (now->child[] == NULL)
- {
- this->Delete_point (x);
- return NULL;
- }
- for (now = now->child[]; now->child[]; now = now->child[]);
- this->Delete_point (x);
- if (now == NULL)
- return now;
- this->Splay (now);
- return now;
- }
- S_D *Find_Prefix (int x)
- {
- this->Insert (x);
- S_D *now = Root;
- if (now->child[] == NULL)
- {
- this->Delete_point (x);
- return NULL;
- }
- for (now = now->child[]; now->child[]; now = now->child[]);
- this->Delete_point (x);
- if (now == NULL)
- return now;
- this->Splay (now);
- return now;
- }
- public :
- int Flandre_Scarlet;
- void Insert (int x)
- {
- if (Root == NULL)
- {
- Root = new S_D ;
- Root->key = x;
- return ;
- }
- S_D *now = Root, *Father;
- for (; ;Father = now, now = now->child[x > now->key])
- {
- if (now == NULL)
- {
- now = new S_D;
- now->key = x;
- now->father = Father;
- Father->child[x > Father->key] = now;
- this->Splay (now);
- return ;
- }
- if (x == now->key)
- {
- now->weigth ++;
- this->Splay (now);
- return ;
- }
- }
- }
- void Cut (int x)
- {
- int Need = Min_N - Flandre_Scarlet;
- S_D *now = this->Find_Prefix (Need);
- if (now != NULL)
- this->Delete_tree (now->key);
- }
- int Query (int x)
- {
- S_D *now = Root;
- for (register int res = ; ; )
- {
- if (now->child[] && x < now->child[]->size)
- now = now->child[];
- res += (now->child[] ? now->child[]->size : ) + now->weigth;
- if (x <= res)
- return now->key;
- x -= res;
- now = now->child[];
- }
- }
- void Change (int x)
- {
- Flandre_Scarlet += x;
- return ;
- }
- int Query_Size ()
- {
- return Root->size;
- }
- };
- Splay_Tree_Type Splay;
- int main (int argc, char *argv[])
- {
- freopen ("cashier.in", "r", stdin);
- freopen ("cashier.out", "w", stdout);
- int N;
- read (N);
- read (Min_N);
- char type[];
- register int Size;
- for (int x; N --; )
- {
- scanf ("%s", type);
- read (x);
- if (type[] == 'I')
- Splay.Insert (x);
- else if (type[] == 'S')
- Splay.Change (-x);
- else if (type[] == 'A')
- Splay.Change (x);
- else
- {
- Splay.Cut (x);
- Size = Splay.Query_Size ();
- if (x > Size)
- puts ("-1");
- else
- printf ("%d\n", Splay.Query (Size - x) + Splay.Flandre_Scarlet);
- }
- }
- printf ("%d", Answer);
- return ;
- }
- /*
- 20 0
- I 4
- F 1
- I 6
- S 9
- F 14
- I 6
- I 7
- A 8
- I 3
- F 2
- I 9
- I 6
- I 6
- S 3
- S 5
- I 6
- F 1
- I 3
- A 2
- F 5
- */
- /*
- 4
- -1
- 14
- 7
- 3
- 5
- */
(WA)BZOJ 1503: [NOI2004]郁闷的出纳员的更多相关文章
- BZOJ 1503: [NOI2004]郁闷的出纳员
1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 10526 Solved: 3685[Submit][Stat ...
- BZOJ 1503: [NOI2004]郁闷的出纳员 splay
1503: [NOI2004]郁闷的出纳员 Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作 ...
- bzoj 1503: [NOI2004]郁闷的出纳员 Treap
1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 6263 Solved: 2190[Submit][Statu ...
- bzoj 1503: [NOI2004]郁闷的出纳员 -- 权值线段树
1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec Memory Limit: 64 MB Description OIER公司是一家大型专业化软件公司,有着数以万计的员 ...
- 1503: [NOI2004]郁闷的出纳员 (SBT)
1503: [NOI2004]郁闷的出纳员 http://www.lydsy.com/JudgeOnline/problem.php?id=1503 Time Limit: 5 Sec Memory ...
- bzoj 3224 NOI2004郁闷的出纳员
NOI2004郁闷的出纳员 2013年12月26日6,1818 输入描述 Input Description 第一行有两个非负整数n和min.n表示下面有多少条命令,min表示工资下界. 接下来的n行 ...
- 【BZOJ】1503: [NOI2004]郁闷的出纳员(Splay)
http://www.lydsy.com/JudgeOnline/problem.php?id=1503 这题没有看题解就1a了-好开心,, 其实后面去看题解发现他们的都很麻烦,其实有种很简单的做法: ...
- 1503. [NOI2004]郁闷的出纳员【平衡树-splay】
Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的 工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经 ...
- 1503: [NOI2004]郁闷的出纳员
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 13723 Solved: 4989[Submit][Status][Discuss] Descripti ...
随机推荐
- Activate注解
Activate注解 被该注解修饰的接口,扩展类可能会被加载 ProtocolFilterWrapper.buildInvokerChain @Documented @Retention(Retent ...
- Linux下/etc/login.defs文件
/etc/login.defs文件定义了与/etc/password和/etc/shadow配套的用户限制设定.这个文件是需要的,缺失并不会影响系统的使用,但是也许会产生意想不到的错误. 如果/etc ...
- 音视频入门-02-RGB拼图
* 音视频入门文章目录 * 图片 & 像素点 & RGB 平时浏览的图片看不出像素点: 图片放大时,可以看出图片是一个个像素点组成的: 每个像素点的颜色可以用 RGB 表示: RGB ...
- codefroce 854 A.Fraction
题解:贪心,每次从能够出发的飞机中取一个最大的就好啦,用一个队列维护一下~ ac代码: #include <cstdio> #include <iostream> #inclu ...
- (十四)角色管理(Ztree插件的基本使用)
1. 建表 角色表 菜单表 角色-菜单(这个表中的role_id和menuu_id都不能被设置为主键,否则当插入一个新角色的时候,一个角色可能拥有多个菜单(role_id重复),一个菜单可能被多个角色 ...
- 上传文件-layui+ashx
public void ProcessRequest (HttpContext context) { if (true) { context.Response.ContentType = " ...
- .net Core CLR
.net Core CLR是开源的.大部分文件是C++写成.这样他就可以编译后再不同的平台运行. https://github.com/dotnet/coreclr
- Flutter 自定义绘制 View
在 Flutter 中自定义 View 有两种方式: 组合已有控件 自定义绘制 如何自定义绘制 有两个类做这件事情: CustomPaint :会在绘制阶段提供一个 Canvas 画布 CustomP ...
- [LeetCode] 22. 括号生成 ☆☆☆(回溯)
描述 给出 n 代表生成括号的对数,请你写出一个函数,使其能够生成所有可能的并且有效的括号组合. 例如,给出 n = 3,生成结果为: [ "((()))", "(()( ...
- element-ui Drawer抽屉组件封装
<template> <div class="com"> <el-drawer title="我是标题" :visible.syn ...