有人说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. Arcgis for JS实现台风运动路径与影像范围的显示

    首先,看看详细的效果: 初始化状态 绘制中 绘制完毕 首先,组织数据.我组织的数据是JSON的,数据的详细形式例如以下: 其次,实现思路. 1.加入显示路径. 依据起始点,生成polyline的JSO ...

  2. weblogic生产、开发模式互转

    生产模式与开发模式转换: 1.生产模式-->开发模式     将%DOMAIN_HOME%\config\config.xml文件中<production-mode-enabled> ...

  3. BitNami-Redmine安装和VisualSVN-Server配合使用

    原文:BitNami-Redmine安装和VisualSVN-Server配合使用 BitNami-Redmine安装和VisualSVN-Server配合使用 2011-05-04 10:48:22 ...

  4. 【腾讯开源】Android性能测试工具APT使用指南

    [腾讯开源]Android性能测试工具APT使用指南 2014-04-23 09:58 CSDN CODE 作者 CSDN CODE 17 7833 腾讯 apt 安卓 性能测试 开源 我们近日对腾讯 ...

  5. 网页头一定要加的代码段(加注版)一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10

      网页头部常见的一段代码 <!--[if lt IE 7 ]><html class="ie6"><![endif]--> <!--[i ...

  6. Android项目--tabhost

    所有牵扯到自定义布局的layout中尽量用RelativeLayout 在通讯录中如果像小米手机的UI那就是viewpager,在这里,我们做成静态的.通过tabhost来做. 1.布局 a) 直接用 ...

  7. php和表单(1)

    先来一段处理表单的html代码(test.html) <form action="index.php" method="post"> name : ...

  8. 学习GDI+ (1)

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. WCF Restful Service的服务

    构建基于WCF Restful Service的服务 前言 传统的Asmx服务,由于遵循SOAP协议,所以返回内容以xml方式组织.并且客户端需要添加服务端引用才能使用(虽然看到网络上已经提供了这方面 ...

  10. Ecological Premium - UVa10300

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10300.html 题目描述 Pr ...