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 ...
随机推荐
- 【分页问题】elasticsearch 深分页问题以及解决方法
本文主要参考: 1.https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html ...
- hdu 6430 线段树 暴力维护
Problem E. TeaTree Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- js的重载
1.重载 //重载(个数不同,类型不同)function prop(){var firstP = document.getElementById("p");if(arguments ...
- Python内置函数(9)——callable--转载
英文文档: callable(object) Return True if the object argument appears callable, False if not. If this re ...
- python 在列表中添加元组元素,按照元组第一个值进行排序
>>> import bisect >>> scores = [(, , , , 'python')] >>> bisect.insort(sco ...
- python 判断列表的包含关系
def is_Sublist(l, s): sub_set = False if s == []: sub_set = True elif s == l: sub_set = True elif le ...
- tp5.1 Env使用
5.1版本取消了所有的系统常量,原来的系统路径变量改为使用Env类获取(需要引入think\facade\Env) echo "app_path=========".Env::ge ...
- redis持久化策略
redis是内存数据库,它把数据存储在内存中,这样在加快读取速度的同时也对数据安全性产生了新的问题,即当redis所在服务器发生宕机后,redis数据库里的所有数据将会全部丢失. 为了解决这个问题,r ...
- 【Python】实现对大文件的增量读取
背景 前段时间在做一个算法测试,需要对源于日志的数据进行分析才能获取到结果:日志文件较大,所以想要获取数据的变化曲线,增量读取是最好的方式. 网上有很多人的技术博客都是写的用for循环readline ...
- hadoo异常——org.apache.hadoop.security.UserGroupInformation: PriviledgedActionException
2013-08-20 10:36:17,728 INFO org.apache.hadoop.http.HttpServer: listener.getLocalPort() returned 500 ...