【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),每个操作可以交 ...
随机推荐
- adb 修改system文件
1. $ adb push SecureSetting.apk /sdcard/ // 上传要安装的文件,为安装做准备. 2. $ adb shell 3. $ su // 切换到 ...
- ASP.NET MVC5学习笔记之Action参数模型绑定基本过程
当我们在Controller中定义一个Action,通常会定义一个或多个参数,每个参数称为一个模型,ASP.NET MVC框架提供了一种机制称为模型绑定,会尝试自动从请求的信息中实例化每一个模型并赋值 ...
- 关于frameset中指定区域回退的实现
指定区域(Frame)的回退,网上大都写的是用 window.parent.window.mainFrame.rightFrame.history.back();来进行回退,但是我这边就是不行,一直 ...
- R语言的日期运算
写hive SQL查询, 需要从导入的参数, 自动累加日期. 从而实现一个自动的,多个日期的统计过程 R语言的日期运算超级简单. > test<-Sys.Date() > test ...
- openstack命令
整理了Openstack命令: openstack aggregate add host openstack aggregate createopenstack aggregate deleteope ...
- db2建立表空间
--缓冲池 CREATE BUFFERPOOL EMP_BUF_POOL IMMEDIATE ALL DBPARTITIONNUMS SIZE 250 NUMBLOCKPAGES 0 PAG ...
- 一篇文章教你读懂Makefile
makefile很重要 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professiona ...
- Php+Redis 实现Redis提供的lua脚本功能
<?php require_once "predis-0.8/autoload.php"; $config['schema'] = 'tcp'; $config['host' ...
- android获取手机录
在Android开发中,读取手机通讯录中的号码是一种基本操作,但是由于Android的版本众多,所以手机通讯录操作的代码比较纷杂,在本文中进行一下总结. Android1.5是现在的Android系统 ...
- 使用VMDepot镜像快速部署CKAN开放数据门户
最新发布的CKAN VMDepot镜像针对中国用户强化了中文支持,提升了与MS Office办公软件的互操作性,并集成了常用插件和最佳实践配置参数. 使得CKAN原本十分复杂繁琐的部署流程变得非常简单 ...