https://www.luogu.org/problemnew/show/2073

自己yy,明显错

#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + ;
const int oo = ; #define gc getchar() struct Node{
int w, b, bef;
}flower[N];
int Ans1, Ans2, opt, W, B, Max, Min;
map<int, bool> Map;
int js = , tot = ; inline int read(){
int x = , f = ; char c = gc;
while(c < '' || c > '') {if(c == '-') f = -; c = gc;}
while(c >= '' && c <= '') x = x * + c - '', c = gc;
return x * f;
} int main()
{
Max = ;
Min = ;
opt = read();
while(opt != ) opt = read();
flower[Max].w = read(); flower[Max].b = read(); Map[flower[Max].w] = ;
flower[Max].bef = ;
while(true){
opt = read();
if(opt == -) break;
if(opt == ){
flower[++ js].w = read(); flower[js].b = read();
W = flower[js].w; B = flower[js].b;
if(Map[W]) {js --; continue ;} else tot ++, Map[W] = ;
if(W > flower[Max].w || ! flower[Max].w) {flower[js].bef = Max; Max = js;}
if(W < flower[Min].w || ! flower[Min].w) {flower[js].bef = Min; Min = js;}
}
else if(opt == ){
if(tot <= ) continue;
int ma = Max;
Map[flower[Max].w] = ;
flower[Max].w = ; flower[Max].b = ;
Max = flower[ma].bef; flower[ma].bef = ;
tot --;
}
else {
if(tot <= ) continue;
int mi = Min;
Map[flower[Min].w] = ;
flower[Min].w = ; flower[Min].b = ;
Min = flower[mi].bef; flower[mi].bef = ;
tot --;
}
}
for(int i = ; i<= N - ; i ++)
Ans1 += flower[i].w, Ans2 += flower[i].b;
cout << Ans1 << " " << Ans2; return ;
}
/*
1 2 2
1 7 20
3
1 16 3
1 2 16
2
-1 */

以权值为下标建立权值线段树

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ls jd<<1
#define rs jd<<1|1 using namespace std;
const int N = 1e6 + ;
const int inf = 0x7f7f7f7f; int opt;
bool vis[N];//用来判重;
struct Tree {int l, r, sumw, sumc, Min,Max;} T[N<<]; void build(int jd, int ll, int rr) {
T[jd].l = ll, T[jd].r = rr, T[jd].Min = inf;
if(ll == rr) return;
int m = ll + rr >> ;
build(ls, ll, m), build(rs, m + , rr);
} void update(int jd, int pos, int val1, int val2, int val3, int val4) {
if(T[jd].l == pos && T[jd].r == pos) {
T[jd].sumc = val1;
T[jd].sumw = val2;
T[jd].Min = val3;
T[jd].Max = val4;
return;
}
if(T[ls].r >= pos) update(ls, pos, val1, val2, val3, val4);
else update(rs, pos, val1, val2, val3, val4);
T[jd].sumc = T[ls].sumc + T[rs].sumc;
T[jd].sumw = T[ls].sumw + T[rs].sumw;
T[jd].Min = min(T[ls].Min, T[rs].Min);
T[jd].Max = max(T[ls].Max, T[rs].Max);
} int main()
{
int n = N - ;
build(, , n);
while(scanf("%d", &opt) == && opt != -) {
int w, c;
if(opt == ) {
scanf("%d %d", &w, &c);
if(vis[c]) continue;
update(, c, c, w, c, c);
vis[c] = true;
}
if(opt == ) {
if(T[].Min == inf) continue;//此时无花,下同;
vis[T[].Min] = false, update(, T[].Min, , , inf, );
}
if(opt == ) {
if(T[].Max == ) continue;
vis[T[].Max] = false, update(, T[].Max, , , inf, );
}
}
printf("%d %d",T[].sumw, T[].sumc);
}

[Luogu] 送花的更多相关文章

  1. 【题解】Luogu P2073 送花

    原题传送门 这题需要用到Splay 我们用一棵splay维护金钱 考虑c<=1000000 我们珂以把每种价格现在对应的美丽值存在一个a数组中 这样讲有珂能不太清楚qaq,还是对着操作一个一个讲 ...

  2. luogu P2073 送花 线段树

    思路&心路 一眼认定沙比提 写的比较慢,写了1小时吧 开心的交上去 卧槽,只有20? 不服不服,拿着题解的代码去对拍 Emma,<100没问题 100000数据错了,还只是错了一个数据 ...

  3. [Luogu 2073] 送花

    很容易想到的平衡树,加个维护区间和. 只需要插入和删除操作即可. kth其实都不用的,最小和最大可以从根节点log n一直向左/一直向右跑到叶子节点而求得. 记得每插入完一个点一定要更新区间和!!更新 ...

  4. Luogu P2073 送花 set

    这题...一眼set...但是打了一会儿.. 记录一下每个价格对应的美丽度,顺便充当vis数组,如果美丽度不为0,说明set里已经有了... 删除好说,删*s.begin()和*--s.end()就好 ...

  5. Luogu P2073 送花

    权值线段树的模板题 然而AC后才发现,可以用\(\tt{set}\)水过-- 权值线段树类似于用线段树来实现平衡树的一些操作,代码实现还是比较方便的 #include<iostream> ...

  6. Luogu 魔法学院杯-第二弹(萌新的第一法blog)

    虽然有点久远  还是放一下吧. 传送门:https://www.luogu.org/contest/show?tid=754 第一题  沉迷游戏,伤感情 #include <queue> ...

  7. luogu p1268 树的重量——构造,真正考验编程能力

    题目链接:http://www.luogu.org/problem/show?pid=1268#sub -------- 这道题费了我不少心思= =其实思路和标称毫无差别,但是由于不习惯ACM风格的题 ...

  8. [luogu P2170] 选学霸(并查集+dp)

    题目传送门:https://www.luogu.org/problem/show?pid=2170 题目描述 老师想从N名学生中选M人当学霸,但有K对人实力相当,如果实力相当的人中,一部分被选上,另一 ...

  9. [luogu P2647] 最大收益(贪心+dp)

    题目传送门:https://www.luogu.org/problem/show?pid=2647 题目描述 现在你面前有n个物品,编号分别为1,2,3,--,n.你可以在这当中任意选择任意多个物品. ...

随机推荐

  1. C语言下进制的使用

    进制规则 十进制 以正常数字1-9开头,如123 八进制 以数字0开头,如0123 十六进制 以0x开头,如0X123 二进制 C语言不能直接书写二进制数 案例如下 int main() { int ...

  2. MySQL监控&性能瓶颈排查

    监控的意义&目的 业务/数据库服务是否可用 通过事务实时性能数据变化感知业务的变化 数据库性能变化趋势判断服务器资源是否足够 数据可靠性 业务数据是否可靠 服务可用,不代表数据就是正确的 有可 ...

  3. ubuntu修改密码

    ubuntu修改密码 本文链接:https://blog.csdn.net/heybob/article/details/9095727 修改root密码: 1,$sudo su,输入密码进入root ...

  4. [UOJ#404][CTSC2018]组合数问题(79分,提交答案题,模拟退火+匈牙利+DP)

    1.4.5.6.10都是op=1的点,除4外直接通过模拟退火调参可以全部通过. #include<cmath> #include<ctime> #include<cstd ...

  5. vue常用时间修饰符记录

    1.stop:阻止冒泡 如下:正常情况下,我们点击最内层的inner_inner的时候,事件会向上冒泡,inner 和outer也会执行.我们在inner_inner事件加上.stop修饰符,就会阻止 ...

  6. Java8新特性 - Optional容器类

    Optional 类(java.util.Optional) 是一个容器类,代表一个值存在或不存在,原来用null 表示一个值不存在,现在Optional 可以更好的表达这个概念.并且可以避免空指针异 ...

  7. springboot启动流程(目录)

    springboot出现有段时间了,不过却一直没有怎么去更多地了解它.一方面是工作的原因,另一方面是原来觉得是否有这个必要,但要持续做java似乎最终逃不开要去了解它的命运.于是考虑花一段时间去学习一 ...

  8. jQuery标签操作

    样式操作 样式类操作 //添加指定的css类名 $('元素选择器')addClass('类名'); //移除指定的css类名 removeClass(); //判断样式存不存在 hasClass(); ...

  9. 等保测评中与oracle有关的工作

    等保2.0包含硬件.存储.中间件.数据库各方面的安全规范,现把与Oracle数据库有关的内容整理如下,供参考: 一.安全计算环境 1.身份鉴别: a,应对登陆的用户进行身份标识和鉴别,身份标识具有唯一 ...

  10. win10 下的anaconda3 安装(2019.06.04最新)

    最近电脑重装系统后,安装anaconda 发现有一些新的变动,容易出现一些新的问题,现在记录下来.(现在根据清华镜像的最新公告,清华anaconda 已经恢复,可以直接换成清华镜像的源了) 1 安装 ...