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 ...
随机推荐
- ubuntu16.04深度学习环境的配置【转】
本文转载自:https://my.oschina.net/u/3837179/blog/1920756 在ubuntu中配置GPU的深度学习环境相较于win问题要多很多,这几天琢磨了一下Ubuntu下 ...
- Linux下停止没有关闭的远程登陆终端
脚本如下: #!/bin/shTTY_LOG=tty_logTTY_LOG1=tty_log1USER_NAME=`whoami`#echo ${USER_NAME}who|grep ${USER_N ...
- 【热更新IK词典】ElasticSearch IK 自动热更新原理与实现
一.热更新原理 elasticsearch开启加载外部词典功功能后,会每60s间隔进行刷新字典.具体原理代码如下所示: public void loadDic(HttpServletRequest r ...
- 【安装】Nginx安装
系统平台:CentOS release 6.5 (Final) 64位. 安装编译工具及库文件 yum -y install make zlib zlib-devel gcc-c++ libtool ...
- java方法和本地方法
java中的方法有两种,java方法和本地方法. java方法:是由java语言编写,编译成字节码,存储在class文件中的.java方法是与平台无关的. 本地方法:本地方法是由其他语言(如C.C++ ...
- window下安装redis报错: creating server tcp listening socket 127.0.0.1:6379: bind No error
window下安装redis报错: creating server tcp listening socket 127.0.0.1:6379: bind No error 解决: 如果没有配置环境,在安 ...
- (转载)CUDA、tensorflow与cuDNN的版本匹配问题
转载:https://blog.csdn.net/MahoneSun/article/details/80809042 CUDA.tensorflow与cuDNN的版本匹配问题 一.问题现象 CUDA ...
- tomcat config https 443
设置https: <Connector port="443" protocol="HTTP/1.1" SSLEnabled="true" ...
- Uva 12304 - 2D Geometry 110 in 1!
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- photoswipe图片滑动插件使用
第一步: 引入jss和css文件 <!-- Core CSS file --> <link rel="stylesheet" href="path/t ...