[Luogu] 送花
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] 送花的更多相关文章
- 【题解】Luogu P2073 送花
原题传送门 这题需要用到Splay 我们用一棵splay维护金钱 考虑c<=1000000 我们珂以把每种价格现在对应的美丽值存在一个a数组中 这样讲有珂能不太清楚qaq,还是对着操作一个一个讲 ...
- luogu P2073 送花 线段树
思路&心路 一眼认定沙比提 写的比较慢,写了1小时吧 开心的交上去 卧槽,只有20? 不服不服,拿着题解的代码去对拍 Emma,<100没问题 100000数据错了,还只是错了一个数据 ...
- [Luogu 2073] 送花
很容易想到的平衡树,加个维护区间和. 只需要插入和删除操作即可. kth其实都不用的,最小和最大可以从根节点log n一直向左/一直向右跑到叶子节点而求得. 记得每插入完一个点一定要更新区间和!!更新 ...
- Luogu P2073 送花 set
这题...一眼set...但是打了一会儿.. 记录一下每个价格对应的美丽度,顺便充当vis数组,如果美丽度不为0,说明set里已经有了... 删除好说,删*s.begin()和*--s.end()就好 ...
- Luogu P2073 送花
权值线段树的模板题 然而AC后才发现,可以用\(\tt{set}\)水过-- 权值线段树类似于用线段树来实现平衡树的一些操作,代码实现还是比较方便的 #include<iostream> ...
- Luogu 魔法学院杯-第二弹(萌新的第一法blog)
虽然有点久远 还是放一下吧. 传送门:https://www.luogu.org/contest/show?tid=754 第一题 沉迷游戏,伤感情 #include <queue> ...
- luogu p1268 树的重量——构造,真正考验编程能力
题目链接:http://www.luogu.org/problem/show?pid=1268#sub -------- 这道题费了我不少心思= =其实思路和标称毫无差别,但是由于不习惯ACM风格的题 ...
- [luogu P2170] 选学霸(并查集+dp)
题目传送门:https://www.luogu.org/problem/show?pid=2170 题目描述 老师想从N名学生中选M人当学霸,但有K对人实力相当,如果实力相当的人中,一部分被选上,另一 ...
- [luogu P2647] 最大收益(贪心+dp)
题目传送门:https://www.luogu.org/problem/show?pid=2647 题目描述 现在你面前有n个物品,编号分别为1,2,3,--,n.你可以在这当中任意选择任意多个物品. ...
随机推荐
- IEEE754浮点数
前言 Go语言之父Rob Pike大神曾吐槽:不能掌握正则表达式或浮点数就不配当码农! You should not be permitted to write production code if ...
- java实现HTTP请求 HttpUtil
示例: package com.sensor.utils; import java.net.HttpURLConnection; import java.net.URL; public class H ...
- Docker 镜像 && 容器的基本操作
镜像 && 容器 docker 镜像好比操作系统的镜像(iso) docker 容器好比是已安装运行的操作系统 所以说 docker 镜像文件运行起来之后,就是我们所说的 docker ...
- vue 做的tabBar组件
效果如下 调用 <tabbar :selected='selected'></tabbar> 组件 <template> <div class='tabbar ...
- PHP原生EXCEL导出带样式无插件无乱码实现
PHP原生EXCEL导出 经测试 带样式 无插件 无乱码,不需要引入任何插件,不需要修改任何编码 (使用时只需要修改引入php数据库配置文件.修改thead tbody中的数据即可.根据自己的需要去接 ...
- 【日语】【ZZ】日语人称小结
[ZZ]日语人称小结 日语中有关人称的词很多,也有不少朋友问 现整理了一下,希望能对那些不太清楚的朋友有点帮助 如果您认为在下有写错的地方,或者您有什么高见,请不吝赐教 第一人称 “我” 1.私 わた ...
- 在SAP除了使用Cordova生产移动应用外,还有这种方式
本文和Jerry过去的文章不太一样,算不上Jerry的知识分享,只是记录一下Jerry用React-Native把应用安装到Android手机上遇到的一些问题,方便以后查看. Jerry的同事Leo用 ...
- 使用abapGit在ABAP On-Premises系统和SAP云平台ABAP环境之间进行代码传输
SAP ABAP顾问朋友们,应该都使用过SAPLink这个工具.如果两个ABAP Netweaver系统没有建立起传输路径时,我们无法使用标准的SE10事务码创建传输请求的方式进行这两个系统间的代码传 ...
- RocketMQ——角色与术语详解
原文地址:http://jaskey.github.io/blog/2016/12/15/rocketmq-concept/ RocketMQ——角色与术语详解 2016-12-15 THU 15:4 ...
- js调用正则表达式
//验证是否为正整数 function isPositiveInteger(s) { var re = /^[0-9]+$/; return re.test(s); } if (exchangeCou ...