【CodeForces】【311C】Fetch the Treasures
最短路
神题一道……
//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的更多相关文章
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- 【Codeforces Round #438 C】 Qualification Rounds
[链接]h在这里写链接 [题意] 给你n个问题,每个人都知道一些问题. 然后让你选择一些问题,使得每个人知道的问题的数量,不超过这些问题的数量的一半. [题解] 想法题. 只要有两个问题. 这两个问题 ...
- 【Codeforces Round #438 B】Race Against Time
[链接]h在这里写链接 [题意] 时针.分钟.秒针走不过去. 问你从t1时刻能不能走到t2时刻 [题解] 看看时针.分钟.秒针的影响就好. 看看是不是在整时的位置就好. 然后看看影响到x不能到y; 然 ...
- 【Codeforces Round #438 A】Bark to Unlock
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举它是在连接处,还是就是整个字符串就好. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc+ ...
- 【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 ...
- 【Codeforces 321E / BZOJ 5311】【DP凸优化】【单调队列】贞鱼
目录 题意: 输入格式 输出格式 思路: DP凸优化的部分 单调队列转移的部分 坑点 代码 题意: 有n条超级大佬贞鱼站成一行,现在你需要使用恰好k辆车把它们全都运走.要求每辆车上的贞鱼在序列中都是连 ...
- 【codeforces contest 1119 F】Niyaz and Small Degrees
题目 描述 \(n\) 个点的树,每条边有一个边权: 对于一个 \(X\) ,求删去一些边后使得每个点的度数 \(d_i\) 均不超过 \(X\) 的最小代价: 你需要依次输出 \(X=0 \to n ...
- 【codeforces #282(div 1)】AB题解
A. Treasure time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【搜索】【并查集】Codeforces 691D Swaps in Permutation
题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...
随机推荐
- python restful 框架之 eve 外网访问设置
官网地址: http://python-eve.org/ 配合mongodb进行crud使用起来很方便,但是部署的时候遇到一个问题,按照官网和Deom说的,servername使用 '127.0.0. ...
- JS获取网页属性包括宽、高等
JS获取网页属性包括宽.高等. function getInfo() { // www.jbxue.com var s = ""; s += " 网页可见区域宽:&q ...
- Incorrect integer value: '' for column 'id' at row 1
最近在写个查询 插入语句的时候 我是这么写的 insert into test values('',$row[contentid],'".$tn."'); 结果搞死没插入进去 然 ...
- PHP通过IP 获取 地理位置(实例)
发布:JB02 来源:脚本学堂 分享一例php代码,实现通过IP地址获取访问者的地理位置,在php编程中经常用到,有需要的朋友参考下吧.本节内容:PHP通过IP获取地理位置 例子: 复制代码代码 ...
- Yii框架中使用PHPExcel导出Excel文件
最近在研究PHP的Yii框架,很喜欢,碰到导出Excel的问题,研究了一下,就有了下面的方法: 1.首先在config\main.php中添加对PHPExcel的引用,我的方式是这样: 1 2 3 4 ...
- 用delphiXE7 dbExpress Framework提供的功能获取数据表信息
uses + Data.DBXMetaDataNames procedure TMainForm.Button2Click(Sender: TObject);var Cmd: TDBXComman ...
- 检测openOffice关闭 自动重启
参考http://my.oschina.net/UpBoy/blog/301193 bat解释:循环检测任务列表找到soffice.exe,没找到就调用run.bat @echo off :l ...
- p ython笔记第三天
#!/usr/bin/env python# -*- coding:utf-8 -*- # v = "李杰"# for item in v:# print(item)####### ...
- Golang之ring.Ring的Link操作
ring.Ring 是一个环链. 其Link操作规则是: r.Link(s) => t = r.Next r.Next.Prev = s.Prev s.Prev.Next = r.Next r. ...
- MongoDB学习笔记-数据格式及数据类型
JSON JSON是一种简单的数据表示方式,它易于理解.易于解析.易于记忆.但从另一方面来说,因为只有null.布尔.数字.字符串.数组和对象这几种数据类型,所以JSON有一定局限性.例如,JSON没 ...