有人说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)

SPOJ3273

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(平板电视)整理的更多相关文章

  1. STL++?pb_ds平板电视初步探索

    什么是pb_ds? 除了众所周知的STL库,c++还自带了ext库(应该可以这么叫吧),其中有用pb_ds命名的名称空间(俗称平板电视).这个名称空间下有四个数据类型结构.这些都是鲜为人知的.经过测试 ...

  2. pb_ds(平板电视)简介

    据说NOI赛制可以用pbds,故整理常用方法: 1.splay 所需声明及头文件: #include <ext/pb_ds/tree_policy.hpp> #include <ex ...

  3. NOIP模板整理计划

    先占个坑 [update]noip结束了,弃了 一.图论 1.单源最短路 洛谷P3371 (1)spfa 已加SLF优化 #include <iostream> #include < ...

  4. ACM算法模板整理

    史诗级ACM模板整理 基本语法 字符串函数 istream& getline (char* s, streamsize n ); istream& getline (char* s, ...

  5. dotNET跨平台相关文档整理

    一直在从事C#开发的相关技术工作,从C# 1.0一路用到现在的C# 6.0, 通常情况下被局限于Windows平台,Mono项目把我们C#程序带到了Windows之外的平台,在工作之余花了很多时间在M ...

  6. UWP学习目录整理

    UWP学习目录整理 0x00 可以忽略的废话 10月6号靠着半听半猜和文字直播的补充看完了微软的秋季新品发布会,信仰充值成功,对UWP的开发十分感兴趣,打算后面找时间学习一下.谁想到学习的欲望越来越强 ...

  7. SQL Server 常用内置函数(built-in)持续整理

    本文用于收集在运维中经常使用的系统内置函数,持续整理中 一,常用Metadata函数 1,查看数据库的ID和Name db_id(‘DB Name’),db_name('DB ID') 2,查看对象的 ...

  8. kafka学习笔记:知识点整理

    一.为什么需要消息系统 1.解耦: 允许你独立的扩展或修改两边的处理过程,只要确保它们遵守同样的接口约束. 2.冗余: 消息队列把数据进行持久化直到它们已经被完全处理,通过这一方式规避了数据丢失风险. ...

  9. JAVA程序员常用软件整理下载

    ********为了大家学习方便,特意整理软件下载如下:*************Java类软件:-------------------------------JDK7.0:http://pan.ba ...

随机推荐

  1. CSS3 实现六边形Div图片展示效果

    原文:CSS3 实现六边形Div图片展示效果 效果图: 实现原理: 这个效果的主要css样式有: 1.>transform: rotate(120deg); 图片旋转 2.>overflo ...

  2. Ora创建job定时执行某存储过程

    --创建job任务,每天晚上8点执行存储过程:por_postrecords-- declare job number; begin sys.dbms_job.submit(job =>job, ...

  3. JQuery Smart UI

    JQuery Smart UI 个人开发的一套使用htm+js的开发框架 SmartUI2.0后续声明 摘要: 感谢很多朋友关注,因为今年一直在另外一个公司做顾问,网络环境管制相当严格,所以一直没有更 ...

  4. POI操作EXCEL之导出Excel(设置有效性,下拉列表引用)

    本人使用的是poi-bin-3.10-FINAL-20140208.zip 版本的poi以下是程序关键代码: //需要引用的类 import java.io.File; import java.io. ...

  5. 在Visual Studio中Git的基本使用

    什么是Git Github : https://github.com/git Pro Git: http://git-scm.com/book Git 是一款免费的.开源的.分布式的版本控制系统.旨在 ...

  6. linux extract rar files

    Extract rar-archives If you need to extract rar files in Linux, you have to download and install unr ...

  7. dedecms模板中使用php代码

    {dede:php} echo “test”: {/dede:php} 使用这段代码之前要在后台的系统--系统基本参数--其它选项 里找到 模板引擎禁用标签: php  将其删除

  8. 大数据之HBase

    大数据之HBase数据插入优化之多线程并行插入实测案例 一.引言: 上篇文章提起关于HBase插入性能优化设计到的五个参数,从参数配置的角度给大家提供了一个性能测试环境的实验代码.根据网友的反馈,基于 ...

  9. 企业架构研究总结(38)——TOGAF架构能力框架之架构能力建设和架构治理

    为了确保架构功能在企业中能够被成功地运用,企业需要通过建立适当的组织结构.流程.角色.责任和技能来实现其自身的企业架构能力,而这也正是TOGAF的架构能力框架(Architecture Capabil ...

  10. 基于MongoDB打造.Net的分布式Session子系统

    基于MongoDB打造.Net的分布式Session子系统 Taobao有她自己的分布式session框架,.net阵营也不能落后了,在下做了个基于MongoDB的支持最多26台MongoDB的分布式 ...