http://codeforces.com/contest/923/problem/B

题意:

有n天,每天产生一堆体积为Vi的雪,每天所有雪堆体积减少Ti

当某一堆剩余体积vi<=Ti时,体积减少vi,雪堆消失

问每天所有雪堆一共减少多少体积

fhq treap

把<=Ti的分裂出来,计算和

>Ti 的 Ti*个数

#include<cstdio>
#include<iostream>
#include<algorithm>using namespace std;#define N 100005int a[N],t[N];
int id[N];int tot;
int root,fa[N],ch[N][2],pri[N];
int siz[N],val[N];
long long sum[N],tag[N];void read(int &x)
{x=0; char c=getchar();while(!isdigit(c)) c=getchar();while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); }
}int newnode(int v)
{siz[++tot]=1;sum[tot]=v;val[tot]=v;pri[tot]=id[tot];return tot;
}void update(int x)
{siz[x]=siz[ch[x][0]]+siz[ch[x][1]]+1;sum[x]=sum[ch[x][0]]+sum[ch[x][1]]+val[x];
}void tagging(int x,int y)
{val[x]-=y;sum[x]-=1LL*siz[x]*y;tag[x]+=y;
}void down(int x)
{if(ch[x][0]) tagging(ch[x][0],tag[x]);if(ch[x][1]) tagging(ch[x][1],tag[x]);tag[x]=0;
}void split(int now,int k,int &x,int &y)
{if(!now) x=y=0;else{if(tag[now]) down(now);if(val[now]<=k){x=now;split(ch[now][1],k,ch[x][1],y);}else{y=now;split(ch[now][0],k,x,ch[y][0]);}update(now);}
}int merge(int x,int y)
{if(x && tag[x]) down(x);if(y && tag[y]) down(y);if(!x || !y)  return x+y;if(pri[x]<pri[y]){ch[x][1]=merge(ch[x][1],y);update(x);return x;}else{ch[y][0]=merge(x,ch[y][0]);update(y);return y;}
}int main()
{int n;read(n);for(int i=1;i<=n;++i) read(a[i]);for(int i=1;i<=n;++i) read(t[i]);for(int i=1;i<=n+2;++i) id[i]=i;random_shuffle(id+1,id+n+1);int x,y,z;for(int i=1;i<=n;++i) {//insert(a[i]);
        split(root,a[i],x,y);root=merge(merge(x,newnode(a[i])),y);split(root,t[i],x,y);cout<<sum[x]+1LL*t[i]*siz[y]<<' ';if(y) tagging(y,t[i]);root=y;}return 0;
}    

转载于:https://www.cnblogs.com/TheRoadToTheGold/p/8590473.html

Codeforces 923 B. Producing Snow相关推荐

  1. codeforces 948C / 923B Producing Snow 【优先队列+思维】

    戳我 传送至 Producing Snow 戳我 到参考网站 **题意:**每天产生一堆雪,大小为v[i]个单位体积,然后每天对应一个数值a[i]代表当天温度,然后剩下的每一堆的雪都会减少这个温度的数 ...

  2. Codeforces Round #470 (rated, Div. 2 C. Producing Snow(思维)

    C. Producing Snow time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. cf 923B Producing Snow

    一 原题 C. Producing Snow time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. 【二分】Producing Snow @Codeforces Round #470 Div.2 C

    time limit per test: 1 second memory limit per test: 256 megabytes Alice likes snow a lot! Unfortuna ...

  5. 2018.12.05 codeforces 948C. Producing Snow(堆)

    传送门 维护一个堆. 每次先算出一个都不弹掉的总贡献. 然后把要弹掉的弹掉,并减去它们对应的贡献. 代码: #include<bits/stdc++.h> #define ri regis ...

  6. Producing Snow CodeForces - 948C 优先队列+思维

    题目链接:https://vjudge.net/problem/CodeForces-948C 转自:https://blog.csdn.net/doncoder/article/details/81 ...

  7. 【CodeForces - 768C】Jon Snow and his Favourite Number(思维,技巧,套路,数学异或,循环节,trick)

    题干: Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own streng ...

  8. codeforces 768 C. Jon Snow and his Favourite Number(思维+暴力)

    题目链接:http://codeforces.com/contest/768/problem/C 题意:给出n个数,k个操作,和一个x,每次操作先排序然后对奇数位数进行xor x操作,最后问k次操作后 ...

  9. Producing Snow

    题解:这道题暴力可以出答案,但是会tle tle代码: #include <iostream>using namespace std; const int maxn = 1e5 + 10; ...

最新文章

  1. JAVA SHA1 加密 对应 c# SHA1 加密
  2. 相机模型--A Unifying Theory for Central Panoramic Systems and Practical Implications
  3. 验证数字的正则表达式集
  4. java joptionpane调整大小_JAVA应用性能监控之JVM层GC调优
  5. mvc:default-servlet-handler /说明
  6. 小米8劲敌来了!同是骁龙845,它降价幅度更大
  7. MySQL Data Manipulation Statements
  8. SPP-net学习总结及Python实现
  9. python中文视频教程-中谷教育python中文视频教程(python视频教程) 完整版
  10. 随笔37 JVM内存
  11. 概率论与数理统计(第四版) 课后习题解析 盛骤、谢式千 编|高等教育出版社 大学课后习题答案
  12. 车载android播放器,KX万能播放器
  13. MATLAB以符号形式表示门函数的傅里叶正反变换。
  14. turtle绘制奥运五环
  15. 公众号如何涨粉?会其中一种都可以让你爆粉
  16. linux命令行的杠“-”、杠杠“--”以及无杠
  17. 纤巧精干:爱普生六轴机器人
  18. U盘中的文件夹都变成了.exe文件
  19. ERP开发的一些闲话—之一
  20. 使用Python获取最新疫情数据,制作可视化动态地图,实时展示各地情况

热门文章

  1. 性能超最先进卷积!用Transformer进行图像语义分割!
  2. MIT的周博磊博士如何解释深度学习模型(附PPT)
  3. 卷王李富贵算法每日一题--分治算法(四)--循环比赛
  4. 大数据分析必须要会的数据预处理操作(二)!!!
  5. 不会Git怎么当程序员?十分钟包你会
  6. Pure Pursuit trajectory tracking and Stanley trajectory tracking总结与比较
  7. java indexof 通配符,字符串与含有通配符‘*’的字符串匹配(非正则表达式)
  8. php mysql 单例模式_PHP基于单例模式实现的mysql类
  9. 删除链表的倒数第n个节点 python_LeetCode 19.删除链表的倒数第N个节点(Python)
  10. linux标准输入输出21