最短路


  神题一道……

 //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. RequireJS和AMD规范

    目录 概述 define方法:定义模块 require方法:调用模块 AMD模式小结 配置require.js:config方法 插件 优化器r.js 参考链接 概述 RequireJS是一个工具库, ...

  2. 开篇 hello 内Cool超人

    经过一年时间看到asp.net mvc一直被受微软开发团队的注重.与之相比的silverlight我感觉到有点力不从心.除去silverlight第一次运行要安装Runtime不说,产品不可能只运行在 ...

  3. C# winform combobox控件中子项加删除按钮(原创)

    效果如下图,本人网上搜索资料加上自己的研究终于实现了在combobox子项中加上删除按钮. 一.窗体中的代码: using System; using System.Collections.Gener ...

  4. Java 中的抽象类及接口

    抽象类使用 abstract 关键字修饰,该类即为抽象类. 抽象类的作用: 1.某些情况下,父类约束子类必须包含哪些方法,但不知道子类如何去实现这些方法. 2.可以从多个具有相同特征的类中抽象出一个抽 ...

  5. Sublime Text 2 安装与使用SFTP插件

    http://wbond.net/sublime_packages/sftp/usage http://www.360doc.com/content/13/0603/15/9437165_290170 ...

  6. 亚信联创--java面试题目总结

    这几天投简历,只有两家的HR表示感兴趣.易思卓越和亚信联创,不管怎样如果能有机会面试都一定尽力表现,所以找了找网上的面经,这里先把题目总结一下. 职位要求如下: ------------------- ...

  7. Google搜索镜像

    From:http://www.cnblogs.com/killerlegend/p/3783744.html Date:2014.6.12 By KillerLegend Google 搜索:htt ...

  8. 【转载】学习C#的28条建议

    1. 看得懂的书,请仔细看:看不懂的书,请硬着头皮看:2. 别指望看第一遍书就能记住和掌握什么——请看第二遍.第三遍:3. 学习编程的秘诀是:编程,编程,再编程:4. 请把书上的程序例子亲手输入到电脑 ...

  9. EF 只更新部分字段

    /// 只更新storedAddress数据中的DefaultAddress字段,更新为false /// 将默认地址改为不是默认地址 /// </summary> /// <par ...

  10. xdebug

    必须的有4个(remote_enable 默认没开,所以必要),其它默认值一般可以xdebug.remote_enable=On; //这个是必须xdebug.remote_host=192.168. ...