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. go 错误

    错误 Go 程序使用 error 值来表示错误状态. 与 fmt.Stringer 类似,`error` 类型是一个内建接口: type error interface { Error() strin ...

  2. 调用WebService时加入身份验证,以拒绝未授权的访问

    众所周知,WebService是为企业需求提供的在线应用服务,其他公司或应用软件能够通过Internet来访问并使用这项在线服务.但在有些时候的某些应用服务不希望被未授权访问,那么此时我们可以一下几种 ...

  3. Linux入职基础-1.1_国内开源的主要镜像站

    Linux入职基础-1.1_国内开源的主要镜像站 东北地区: 东北大学  http://mirror.neu.edu.cn 大连理工大学  http://mirror.dlut.edu.cn 大连东软 ...

  4. LeetCode每日一练(1-3)

    题目导航 1. 两数之和 2. 两数相加 3. 无重复字符的最长子串 1. 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的 ...

  5. JSONObject和URL以及HttpURLConnection的使用

    1 将java对象类转成json格式 首先引入依赖jar文件 注意依赖文件的版本号,高版本可能没有对应的类 2 我的实体类中包含内部类注意内部类要public才能被序列化成json格式 import ...

  6. phpcms企业站的一些知识

    头header.html 尾footer.html 主页用index.html 列表页用list.html 单网页用page.html 内容页用show.html {template "co ...

  7. sql server动态分页

    USE RYPlatformManagerDB GO SET ANSI_NULLS, QUOTED_IDENTIFIER ON GO CREATE Proc [dbo].[WEB_PageView] ...

  8. 关于QPS、TPS、PV、UV、GMV、IP、RPS的名词解释!

    名词解释链接:https://blog.csdn.net/jackyrongvip/article/details/98839519

  9. nginx编译安装和功能介绍

    nginx介绍 nginx: engine X,是由1994年毕业于俄罗斯国立莫斯科鲍曼科技大学的同学为俄罗斯rambler.ru公司开发的,开发工作最早从2002年开始,第一次公开发布时间是2004 ...

  10. 【20191118会议】针对华为云CCE 问题总结

    针对华为云CCE问题总结 如何购买CCE集群 可以分为测试环境和生产环境,针对使用范围进行购买集群. 测试环境 可以进行公用 生产环境建议使用单独集群 尤其针对部门大 耦合性不高 ,生产环境 建议使用 ...