bzoj2505: tickets
Description
Input
Output
#include<cstdio>
typedef long long i64;
i64 l,r,p10[];
struct state{
i64 c;
int r;
void operator+=(state w){
c+=w.c;
r=w.r;
}
}f[][][];
struct pos{
int a,b;
}stk1[],stk2[];
int stp1=,stp2=;
int p1=,p2=;
int k,sl[],pl=,sr[],pr=;
int main(){
scanf("%lld%lld%d",&l,&r,&k);
p10[]=;
for(int i=;i<=;++i)p10[i]=p10[i-]*;
for(int j=;j<=;++j){
for(int a=;a<k;++a){
f[][j][a]=(state){a+j>=k,a+j>=k?:a+j};
}
}
for(int i=;i<=;++i){
for(int j=;j<=-i*;++j){
for(int a=;a<k;++a){
state&w=f[i][j][a]=f[i-][j][a];
for(int b=;b<;++b){
w+=f[i-][j+b][w.r];
}
}
}
}
--l;++r;
while(l)sl[++pl]=l%,l/=;
while(r)sr[++pr]=r%,r/=;
pl=pr;
int eq=pr;
while(sl[eq]==sr[eq])--eq;
int cl=,cr=;
for(int i=;i<=pr;++i)cl+=sl[i],cr+=sr[i];
for(int i=;i<eq;++i){
cl-=sl[i],cr-=sr[i];
for(int a=sl[i]+;a<=;++a)stk1[stp1++]=(pos){i-,cl+a};
for(int a=sr[i]-;a>=;--a)stk2[stp2++]=(pos){i-,cr+a};
}
cr-=sr[eq];
for(int a=sl[eq]+;a<sr[eq];++a)stk1[stp1++]=(pos){eq-,cr+a};
while(stp2)stk1[stp1++]=stk2[--stp2];
state w=(state){,};
for(int i=;i<stp1;++i)w+=f[stk1[i].a][stk1[i].b][w.r];
printf("%lld\n",w.c);
return ;
}
bzoj2505: tickets的更多相关文章
- POJ2828 Buy Tickets[树状数组第k小值 倒序]
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 19012 Accepted: 9442 Desc ...
- ACM: FZU 2112 Tickets - 欧拉回路 - 并查集
FZU 2112 Tickets Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u P ...
- Tickets——H
H. Tickets Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this i ...
- POJ 2828 Buy Tickets(线段树 树状数组/单点更新)
题目链接: 传送门 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Description Railway tickets were d ...
- 【poj2828】Buy Tickets
Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...
- [poj2828] Buy Tickets (线段树)
线段树 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must ...
- POJ 2828 Buy Tickets
Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...
- Buy Tickets(线段树)
Buy Tickets Time Limit:4000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- 【poj2828】Buy Tickets 线段树 插队问题
[poj2828]Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in ...
随机推荐
- UVA 12338 Anti-Rhyme Pairs(hash + 二分)题解
题意:给出两个字符串的最大相同前缀. 思路:hash是要hash,不hash是不可能的.hash完之后从头遍历判断超时然后陷入沉默,然后告诉我这能二分orz,二分完就过了,写二分条件写了半天.不要用数 ...
- 基于spring boot admin 做监控的一些问题记录
问题一 各个健康节点权限问题 解决方式 加入权限模块 <dependency> <groupId>org.springframework.boot</groupId> ...
- scrapy中的canonicalize_url【转】
转自:http://www.leyle.com/archives/canonicalize_url.html 思考一下:对url进行规范化处理是否是必须的?因为这一步处理涉及到编码转换,对于一个网页的 ...
- Template Method(模板方法)
意图: 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中.TemplateMethod 使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. 适用性: 一次性实现一个算法的不变的部分, ...
- 如何修改SQL Server 2008数据库服务器名称
在做数据库发布订阅的时候我们经常要碰到要使用服务器名称来进行. 那么我们经常会碰到的问题是,现在开始大量的使用云服,我们只需要一台服务器搭建好环境,做一个备份镜像,还原到其他的服务器上就可以了,但是问 ...
- gif&png&jpg&webp
几种图片格式的区别和联系 1.http://www.tuicool.com/articles/AbUvI3A
- Java Spring-事务管理概述
2017-11-11 23:05:39 事务(Transaction):是逻辑上一组操作,要么全都成功,要么全都失败. 一.事务的特性 原子性:事务不可分割 一致性:事务执行的前后,数据完整性保持一致 ...
- Numpy np.array 相关常用操作
https://www.cnblogs.com/oftenlin/p/7856389.html
- thinkphp3.2验证码在服务器上显示不出来
ThinPHP3.2 验证码 在本地服务器访问可以显示,上传到服务器就不能访问了 /**** * 验证码 */ function code() { $config=array( 'fontSize'= ...
- 108. Convert Sorted Array to Binary Search Tree 109. Convert Sorted List to Binary Search Tree -- 将有序数组或有序链表转成平衡二叉排序树
108. Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascendin ...