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 ...
随机推荐
- Ajax请求304问题
ajax默认是开启缓存的,所以get请求如果路径一样,会先找缓存,如果缓存存在就用缓存. 解决方案: 1.在修改url为动态变化的,如url后面加一个×tamp=Date.parse ...
- C# 版本和.NET 版本以及VS版本的对应关系
https://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Versions http://stackoverflow.com/quest ...
- ZOJ 3747 Attack on Titans
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3747 题意: 现在有n个士兵进行排序,只有G.R.P三种士兵,要求至少有m ...
- 使用IDEA创建基于Gradle构建的JavaWeb项目
环境配置 jdk: 1.8 Gradle: 4.4.1 Tomcat: 9.0.0 One Step! 创建项目,初始化项目结构. 打开我们的IDEA,进入创建项目的界面,勾选Java,Web两个选项 ...
- Visualization data using R and bioconductor.--NCBI
- shell 判断是否是目录
创建一个文件和一个文件夹 touch sss mkdir d test.sh #!/bin/bash echo "enter the name:" read filename if ...
- WPF——RenderTransform特效
WPF: RenderTransform特效 WPF中的变形(RenderTransform)类是为了达到直接去改变某个Silverlight对象的形状(比如缩放.旋转一个元素)的目的而设计的,Ren ...
- Vue学习笔记一:使用vue-cli 创建开发环境
第一步:安装Node.js 点击此处下载 选择对应的安装包,进行安装. 第二步:安装淘宝镜像 有一个问题,使用 npm 会导致网速很慢,对于大陆用户,建议将 npm 的注册表源设置为国内的镜像, ...
- Android手机无线adb
1.首先电脑,手机通过数据线链接电脑,然后通过adb devices 查看到已连接 2.输入:adb tcpip 5555 3.输入:adb connect 222.222.221.137:5555 ...
- Android数据库升级不丢失数据解决方案
在Android开发中,sqlite至关重要,增删查改不多说,难点在于,1,并发,多个线程同时操作数据库.2,版本升级时,如果数据库表中新加了个字段,如何在不删除表的情况下顺利过渡,从而不丢失数据. ...