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. 简单即时通讯、聊天室--java NIO版本

    实现的功能: 运行一个服务端,运行多个客户端.在客户端1,发送消息,其余客户端都能收到客户端1发送的消息. 重点: 1.ByteBuffer在使用时,注意flip()方法的调用,否则读取不到消息. 服 ...

  2. 题解-CTS2019随机立方体

    problem \(\mathtt {loj-3119}\) 题意概要:一个 \(n\times m\times l\) 的立方体,立方体中每个格子上都有一个数,如果某个格子上的数比三维坐标中至少有一 ...

  3. python实现ssh及sftp功能

    1.在Linux上我们通过scp命令实现主机间的文件传送,通过ssh实现远程登录 ,比如 我们经常使用的xshell远程登录工具,就是基础ssh协议实现window主机远程登录Linux主机 下面简单 ...

  4. MySql数据库操作之数据约束

    首先数据库的外键是数据库提供的一种完整性约束.在许多数据库的书上也会介绍到,然而对于外键这个完整性性约束究竟应该在数据库端实现,还是在项目业务端实现很多人有着不同的意见. 个人开发(小型应用).数据库 ...

  5. Pyspark笔记一

    1. pyspark读csv文件后无法显示中文 #pyspark读取csv格式时,不能显示中文 df = spark.read.csv(r"hdfs://mymaster:8020/user ...

  6. 【公有云】在阿里云中申请免费ssl证书

    准备 拥有阿里云账号 拥有域名,最好是在同个账号下,方便操作. 申请证书 第一步:进入申请 第二步:选择证书类型 第三步:支付,就是走个流程,不用给钱 第四步:填写证书信息 第五步:验证域名 第六步: ...

  7. 【深度学习】Precision 和 Recall 评价指标理解

    1. 四种情况 Precision精确率, Recall召回率,是二分类问题常用的评价指标.混淆矩阵如下: 预测结果为阳性 Positive 预测结果为假阳性 Negative 预测结果是真实的 Tr ...

  8. Python语言程序设计:Lab4

    Programming 1.Analysing a Text File Look at the file xian_info.txt which is like this: Xi'an China 8 ...

  9. javascript reduce 前端交互 总计

    sum(){ return this.products.reduce((total,next)=>{ return total + next.price * next.aumout},0) } ...

  10. 用js刷剑指offer(字符串的排列)

    题目描述 题目描述 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 输入 ...