最短路


  神题一道……

 //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 获取当天23点59分59秒 时间戳 (最简单的方法)

    js 获取当天23点59分59秒 时间戳 (最简单的方法) new Date(new Date(new Date().toLocaleDateString()).getTime()+24*60*60* ...

  2. win32 汇编打造 wget 体积3kb

    Demo Code .386 .MODEL flat, stdcall OPTION CASEMAP:NONE Include windows.inc include kernel32.inc inc ...

  3. Creating an API-Centric Web Application[转]

    Creating an API-Centric Web Application 转自 http://hub.tutsplus.com/tutorials/creating-an-api-centric ...

  4. ContactsContract中涉及数据库中的一些列属性值【Written By KillerLegend】

    ContactsContract.Data   http://developer.android.com/reference/android/provider/ContactsContract.Dat ...

  5. Java 装箱 拆箱

    Java 自动装箱与拆箱   ??什么是自动装箱拆箱 基本数据类型的自动装箱(autoboxing).拆箱(unboxing)是自J2SE 5.0开始提供的功能. 一般我们要创建一个类的对象的时候,我 ...

  6. 共享内存 share pool (1):heap /extent /chunk/

    相关概念 CHUNK: Shared pool物理层面上由许多内存块组成,这些内在块称为chunk.但是chunk是大小不一的,在内存中一个chunk是连续的. EXTENT:由多个连续的chunk组 ...

  7. linux命令行下的ftp 多文件下载和目录下载(转)

    目标ftp服务器是一个非标准端口的ftp   1.通过shell登录 #ftp    //shell下输入ftp命令,进入到ftp提示符 >open IP  PORT   //IP ,PORT对 ...

  8. ED/EP系列2《文件结构》

    电子存折/电子钱包应用是为持卡人进行金融交易而设计的一种应用.对于一张金融 IC 卡来说,它可以同时支持电子存折和电子钱包两种应用,也可以只支持其中的一种.卡片上两种应用的存在情况可以由应用类型标识( ...

  9. [原创]PostgreSQL Plus Advanced Server监控工具PEM(三)

    三.使用PEM Client 在PEM Client中连接PEM Server 点击上图所示的按钮或点击菜单-> 第一次连接PEM Server,会有一次导入证书的操作,点击Yes按钮. 接下来 ...

  10. 深度神经网络DNN的多GPU数据并行框架 及其在语音识别的应用

    深度神经网络(Deep Neural Networks, 简称DNN)是近年来机器学习领域中的研究热点,产生了广泛的应用.DNN具有深层结构.数千万参数需要学习,导致训练非常耗时.GPU有强大的计算能 ...