pb_ds(平板电视)整理
有人说BZOJ3040用普通的<queue>中priority_queue搞dijkstra过不了。
我只想说你们的djk可能写的太丑了。
先上代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<ext/pb_ds/priority_queue.hpp>
#define pir pair<ll,int>
using namespace std;
typedef long long ll;
//typedef std::priority_queue<pir,vector<pir>,greater<pir> > heap;
//3840 ms
typedef __gnu_pbds::priority_queue<pir,greater<pir> > heap;//默认是pairing_heap_tag
//3304 ms
const int N=1e6+,M=1e7+;
const ll INF=1e15;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,m,T,rxa,rxc,rya,ryc,rp,a,b;
int x,y,z;
struct node{
int v,w,next;
}e[M];
int cnt,head[N];ll dis[N];bool vis[N];
inline void add(int u,int v,int w){
e[++cnt].v=v;e[cnt].w=w;e[cnt].next=head[u];head[u]=cnt;
}
heap q;
inline void dijkstra(){
int S;
for(int i=;i<=n;i++) dis[i]=INF;
dis[S=]=;
q.push(make_pair(dis[S],S));
while(!q.empty()){
pir t=q.top();q.pop();
int x=t.second;
if(vis[x]) continue;
vis[x]=;
for(int i=head[x];i;i=e[i].next){
int v=e[i].v;
if(!vis[v]&&dis[v]>dis[x]+e[i].w){
dis[v]=dis[x]+e[i].w;
q.push(make_pair(dis[v],v));
}
}
}
}
int main(){
n=read();m=read();
T=read();rxa=read();rxc=read();rya=read();ryc=read();rp=read();
m=m-T;
x=rxc%rp;y=ryc%rp;
a=min(x%n+,y%n+);
b=max(y%n+,y%n+);
while(T--) add(a,b,-*a);
while(m--) x=read(),y=read(),z=read(),add(x,y,z);
dijkstra();
printf("%lld",dis[n]);
return ;
}
对比:
平衡二叉树(Balanced Binary Tree)
| English | Vietnamese |
In this problem, you have to maintain a dynamic set of numbers which support the two fundamental operations
- INSERT(S,x): if x is not in S, insert x into S
- DELETE(S,x): if x is in S, delete x from S
and the two type of queries
- K-TH(S) : return the k-th smallest element of S
- COUNT(S,x): return the number of elements of S smaller than x
Input
- Line 1: Q (1 ≤ Q ≤ 200000), the number of operations
- In the next Q lines, the first token of each line is a character I, D, K or C meaning that the corresponding operation is INSERT, DELETE, K-TH or COUNT, respectively, following by a whitespace and an integer which is the parameter for that operation.
If the parameter is a value x, it is guaranteed that 0 ≤ |x| ≤ 109. If the parameter is an index k, it is guaranteed that 1 ≤ k ≤ 109.
Output
For each query, print the corresponding result in a single line. In particular, for the queries K-TH, if k is larger than the number of elements in S, print the word 'invalid'.
Example
Input
8
I -1
I -1
I 2
C 0
K 2
D -1
K 1
K 2 Output
1
2
2
invalid
#include<cstdio>
#include<ext/pb_ds/assoc_container.hpp>
//pb_ds库这次内置了红黑树(red-black tree)、伸展树(splay tree)和排序向量树(ordered-vector tree,没找到通用译名,故自行翻译)。
//这些封装好的树都支持插入(insert)、删除(erase)、求kth(find_by_order)、求rank(order_of_key)操作,O(logn)内完成
using namespace std;
using namespace __gnu_pbds;
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
tree<int,null_mapped_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>bbt;
//SPOJG++版本稍旧(4.3.2),需要写成null_mapped_type才可以(高级版本可以写null_type)
char in(){
for(char ch=getchar();;ch=getchar()) if(ch>='A'&&ch<='Z') return ch;
}
int main(){
char c;int x;
for(int T=read();T--;){
c=in();x=read();
if(c=='I'){
bbt.insert(x);
}
else if(c=='D'){
bbt.erase(x);
}
else if(c=='K'){
if(x<=bbt.size())
printf("%d\n",*bbt.find_by_order(x-));
else
puts("invalid");
}
else{
printf("%d\n",bbt.order_of_key(x));
}
}
return ;
}
BZOJ3224: Tyvj 1728 普通平衡树
#include<cstdio>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("02")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
ll read(){
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
typedef __gnu_pbds::tree<ll,null_mapped_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> T;
T bbt;ll ans;
int main(){
ll n=read();
for(ll i=,o,k;i<=n;i++){
o=read();k=read();
if(o==) bbt.insert((k<<)+i);else
if(o==) bbt.erase(bbt.lower_bound(k<<));else
if(o==) printf("%d\n",bbt.order_of_key(k<<)+);else
{
if(o==) ans=*bbt.find_by_order(k-);else
if(o==) ans=*--bbt.lower_bound(k<<);else
if(o==) ans=*bbt.lower_bound((k+)<<);
printf("%lld\n",ans>>);
}
}
return ;
}
pb_ds(平板电视)整理的更多相关文章
- STL++?pb_ds平板电视初步探索
什么是pb_ds? 除了众所周知的STL库,c++还自带了ext库(应该可以这么叫吧),其中有用pb_ds命名的名称空间(俗称平板电视).这个名称空间下有四个数据类型结构.这些都是鲜为人知的.经过测试 ...
- pb_ds(平板电视)简介
据说NOI赛制可以用pbds,故整理常用方法: 1.splay 所需声明及头文件: #include <ext/pb_ds/tree_policy.hpp> #include <ex ...
- NOIP模板整理计划
先占个坑 [update]noip结束了,弃了 一.图论 1.单源最短路 洛谷P3371 (1)spfa 已加SLF优化 #include <iostream> #include < ...
- ACM算法模板整理
史诗级ACM模板整理 基本语法 字符串函数 istream& getline (char* s, streamsize n ); istream& getline (char* s, ...
- dotNET跨平台相关文档整理
一直在从事C#开发的相关技术工作,从C# 1.0一路用到现在的C# 6.0, 通常情况下被局限于Windows平台,Mono项目把我们C#程序带到了Windows之外的平台,在工作之余花了很多时间在M ...
- UWP学习目录整理
UWP学习目录整理 0x00 可以忽略的废话 10月6号靠着半听半猜和文字直播的补充看完了微软的秋季新品发布会,信仰充值成功,对UWP的开发十分感兴趣,打算后面找时间学习一下.谁想到学习的欲望越来越强 ...
- SQL Server 常用内置函数(built-in)持续整理
本文用于收集在运维中经常使用的系统内置函数,持续整理中 一,常用Metadata函数 1,查看数据库的ID和Name db_id(‘DB Name’),db_name('DB ID') 2,查看对象的 ...
- kafka学习笔记:知识点整理
一.为什么需要消息系统 1.解耦: 允许你独立的扩展或修改两边的处理过程,只要确保它们遵守同样的接口约束. 2.冗余: 消息队列把数据进行持久化直到它们已经被完全处理,通过这一方式规避了数据丢失风险. ...
- JAVA程序员常用软件整理下载
********为了大家学习方便,特意整理软件下载如下:*************Java类软件:-------------------------------JDK7.0:http://pan.ba ...
随机推荐
- 编程乐趣:C#获取日期所在周、月份第一和最后一天
原文:编程乐趣:C#获取日期所在周.月份第一和最后一天 写了个小功能,需要用到以周为时间段,于是写了个获取周第一和最后一天的方法,获取月份的第一和最后一天就比较简单了.代码如下: public cla ...
- Unity3d在线游戏Socket通讯
网络游戏是一个人的互动娱乐软件应用.因为它是交互式,当然,需要了解对方的通信.这需要通信Socket:我们今天要实现的主角即套接字.Socket的英文原义是"孔"或"插座 ...
- Util应用程序框架公共操作类
随笔分类 - Util应用程序框架公共操作类 Util应用程序框架公共操作类 Util应用程序框架公共操作类(五):异常公共操作类 摘要: 任何系统都需要处理错误,本文介绍的异常公共操作类,用于对业务 ...
- 安装Visual Source Safe 2005 - 初学者系列 - 学习者系列文章
本文介绍微软的文档管理工具Visual Source Safe 2005的安装 从下列地址获取该工具: ed2k://|file|en_vss_2005.iso|108048384|C4BEC1EC3 ...
- EasyUi的快速开发框架
基于EasyUi的快速开发框架 先看图,下边这个简单的增.删.改.查,如果自己写代码实现,这两个页需要多少行代码? 如果再有类似的增.删.改.查,又需要多少行代码? 我最近搞的这个快速开发框架中, ...
- API变了,客户端怎么办?
使用ASP.NET Web Api构建基于REST风格的服务实战系列教程[九]——API变了,客户端怎么办? 系列导航地址http://www.cnblogs.com/fzrain/p/3490137 ...
- 推荐系列:最小与最大[DP+余式定理]
最小与最大 [问题描述] 做过了乘积最大这道题,相信这道题也难不倒你. 已知一个数串,可以在适当的位置加入乘号(设加了k个,当然也可不加,即分成k+1个部分),设这k+1个部分的乘积(如果k=0,则乘 ...
- D11
=-=感觉今天的题目好难... 主要是没有碰到过,所以会觉得不懂怎么写.. 其实现在想想,T1,T2,T3其实都好水..T1其实没有做过还真不会,有做过的话就是个大水题了 T2找最小环..超级裸的,但 ...
- 默认python2.6切换成python27
# 安装修改pythonyum -y install python27 python27-devel python -V; python2.6 -V # 查看当前python版本 这两个应该都 ...
- C# 制作Windows服务安装包
C# 制作Windows服务安装包 这两天公司要用C#写一个windows服务,做成安装安装包.制作的过程中遇到了一些问题,写完之后总结一下.如果以后在用到的话可以可以参考一下,而且由于原来没有做 ...