最短路


  神题一道……

 //CF 311C
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pii pair<int,int>
#define mk make_pair
using namespace std;
typedef long long LL;
LL getint(){
LL v=,sign=; char ch=getchar();
while(ch<''||ch>'') {if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<='') {v=v*+ch-''; ch=getchar();}
return v*sign;
}
const int N=,INF=~0u>>;
/*******************tamplate********************/
priority_queue<pii >H;
LL a[N],d[N],data[],z;
int n,m,k,x,y,L,ed[],f[N*],c[N];
bool b[N]; void add(){
z=getint();
data[++L]=z/k; ed[L]=z%k;
int h=,t=; rep(i,k) f[++t]=i;
while(h<t){
x=f[++h],b[x]=;
F(i,,L){
y=x+ed[i],z=d[x]+data[i]; if(y>=k) y-=k,z++;
if (z<d[y]) {d[y]=z;if(!b[y]) b[y]=,f[++t]=y;}
}
}
while(!H.empty()) H.pop();
F(i,,n)
if(d[a[i]%k]<=a[i]/k && c[i]) H.push(mk(c[i],-i));
}
void dec(){
x=getint(); y=getint();c[x]-=y;
if (d[a[x]%k]<=a[x]/k) H.push(mk(c[x],-x));
}
void pop(){
while(){
if(H.empty()){puts("");return;}
pii o=H.top(); H.pop(); x=-o.second,y=o.first;
if (c[x]==y) {printf("%d\n",y),c[x]=; return;}
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
getint(); n=getint();
m=getint(); k=getint();
memset(d,,sizeof d); d[]=;
F(i,,n){
a[i]=getint(); c[i]=getint();
if (a[i]%k==) H.push(mk(c[i],-i));
}
int ch;
F(i,,m){
ch=getint();
if (ch==) add();
else if(ch==) dec();
else pop();
}
return ;
}

【CodeForces】【311C】Fetch the Treasures的更多相关文章

  1. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  2. 【Codeforces Round #438 C】 Qualification Rounds

    [链接]h在这里写链接 [题意] 给你n个问题,每个人都知道一些问题. 然后让你选择一些问题,使得每个人知道的问题的数量,不超过这些问题的数量的一半. [题解] 想法题. 只要有两个问题. 这两个问题 ...

  3. 【Codeforces Round #438 B】Race Against Time

    [链接]h在这里写链接 [题意] 时针.分钟.秒针走不过去. 问你从t1时刻能不能走到t2时刻 [题解] 看看时针.分钟.秒针的影响就好. 看看是不是在整时的位置就好. 然后看看影响到x不能到y; 然 ...

  4. 【Codeforces Round #438 A】Bark to Unlock

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举它是在连接处,还是就是整个字符串就好. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc+ ...

  5. 【codeforces 718 C&D】C. Sasha and Array&D. Andrew and Chemistry

    C. Sasha and Array 题目大意&题目链接: http://codeforces.com/problemset/problem/718/C 长度为n的正整数数列,有m次操作,$o ...

  6. 【Codeforces 321E / BZOJ 5311】【DP凸优化】【单调队列】贞鱼

    目录 题意: 输入格式 输出格式 思路: DP凸优化的部分 单调队列转移的部分 坑点 代码 题意: 有n条超级大佬贞鱼站成一行,现在你需要使用恰好k辆车把它们全都运走.要求每辆车上的贞鱼在序列中都是连 ...

  7. 【codeforces contest 1119 F】Niyaz and Small Degrees

    题目 描述 \(n\) 个点的树,每条边有一个边权: 对于一个 \(X\) ,求删去一些边后使得每个点的度数 \(d_i\) 均不超过 \(X\) 的最小代价: 你需要依次输出 \(X=0 \to n ...

  8. 【codeforces #282(div 1)】AB题解

    A. Treasure time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  9. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  10. 【搜索】【并查集】Codeforces 691D Swaps in Permutation

    题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...

随机推荐

  1. js获取和设置DOM样式函数cssStyle(类似于jquery的$(elem).css())

    如题,相信这个函数百度一搜一大推,但令人匪夷所思的是这些函数都写的“奇形怪状的”,例如http://www.cnblogs.com/windows7/archive/2010/03/30/170064 ...

  2. Ubuntu12.04卡死的解决方案

    刚开始安装的时候用着还行,不过后来发现用了一会总是会出现卡死的状况 后来看了下ubuntu12.04的内核是3.2,后来把内核升级到3.5发现这种情况不会出现了. 查看内核以及升级内核 uname - ...

  3. Mysql 简单问题汇总(持续更新)

    主从架构相关问题 问题现象:从机连接主机时报错 [ERROR] Slave I/O: error connecting to master 'repl@192.168.0.50:3306' - ret ...

  4. SynchronizationContext一篇

    SynchronizationContext context; 最近写代码用到了这个,特别记录一下. 作用如下: // 摘要: // 提供在各种同步模型中传播同步上下文的基本功能. public cl ...

  5. 实战MySQL集群,试用CentOS 6下的MariaDB-Galera集成版

    说起mysql的集群估计很多人会首先想起mysql自带的replication或者mysql-mmm.mysql-mmm其实也是基于mysql自带的replication的,不过封装的更好用一些,但是 ...

  6. HDU1009

    题意:有n个房子,每个房子里都有老鼠喜欢吃的咖啡豆J[i],但是每个房子都有猫看守,老鼠现在手上有M的猫粮.可以用猫粮换咖啡豆,每只猫都有猫粮的要求F[i].老鼠得到的咖啡豆是J[i]*a%     ...

  7. hdu 5280 Senior's Array

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...

  8. iOS 关于webView的使用方法

    关于webView的使用方法还是比较简单的.直接上代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ...

  9. go语言包与包引用

    go语言中包(package)与java中的包(package)非常类似,都是组织代码的方式,而且都和磁盘上的目录结构存在对应关系. go语言中,包名一般为go代码所在的目录名,但是与java不同的是 ...

  10. shell 基本结构

    就像其他的编程语言一样,shell也有三种基本的结构:顺序结构.分支结构.循环结构.顺序结构就是按照命令的出现顺序依次执行,比较简单.如下分别介绍分支结构和循环结构. 分支结构 格式1: if com ...