[Codeforces-div.1 809C] Find a car

试题分析

莫名结论:\(a_{i,j}=(i-1) xor (j-1) +1\)

然后分成\(i\space xor\space j\)和 \(1\)分别数位dp计算。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm> using namespace std;
#define LL long long inline LL read(){
LL x=0,f=1; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const LL MAXN = 100010;
const LL INF = 2147483600;
const LL Mod = 1e9+7; LL Q,x1,x2,Y1,y2,k;
LL dp[41][5][5][5],f[41][5][5][5];
LL cnt[5],str[5][MAXN+1]; inline void split(LL x,LL k){
for(LL i=1;i<=cnt[k];i++) str[k][i]=0;
cnt[k]=0; while(x){str[k][++cnt[k]]=x&1; x>>=1;}
return ;
}
inline LL calc(LL x,LL y,LL K){
--x,--y; if(x<0||y<0) return 0;
for(int i=33;i>=0;i--)
for(int j=0;j<2;j++)
for(int k=0;k<2;k++)
for(int l=0;l<2;l++)
dp[i][j][k][l]=f[i][j][k][l]=0;
split(x,1); split(y,2); split(K,3);
f[32][1][1][1]=1;
for(LL i=32;i>=1;i--){
for(LL t1=0;t1<2;t1++)
for(LL t2=0;t2<2;t2++)
for(LL t3=0;t3<2;t3++){
if(!f[i][t1][t2][t3]) continue;
//cout<<i<<"="<<t1<<" "<<t2<<" "<<t3<<":"<<f[i][t1][t2][t3]<<" "<<str[1][i]<<" "<<str[2][i]<<endl;
for(LL a=0;a<=(t1?str[1][i]:1);a++){
for(LL b=0;b<=(t2?str[2][i]:1);b++){
if(t1&&a>str[1][i]) continue;
if(t2&&b>str[2][i]) continue;
if(t3&&(a^b)>str[3][i]) continue;
LL nxt1=(t1?(a==str[1][i]):0);
LL nxt2=(t2?(b==str[2][i]):0);
LL nxt3=(t3?((a^b)==str[3][i]):0);
//cout<<"check:"<<i<<" "<<nxt1<<" "<<nxt2<<" "<<nxt3<<":";
f[i-1][nxt1][nxt2][nxt3]+=f[i][t1][t2][t3]; f[i-1][nxt1][nxt2][nxt3]%=Mod;
dp[i-1][nxt1][nxt2][nxt3]+=(dp[i][t1][t2][t3]+1LL*f[i][t1][t2][t3]*((a^b)<<(i-1))%Mod)%Mod;
dp[i-1][nxt1][nxt2][nxt3]%=Mod;
//cout<<" "<<dp[i-1][nxt1][nxt2][nxt3]<<" "<<dp[i-1][nxt1][nxt2][nxt3]<<endl;
}
}
}
} LL s=0;
for(LL i=0;i<2;i++){
for(LL j=0;j<2;j++){
for(LL k=0;k<2;k++)
s+=(dp[0][i][j][k]+f[0][i][j][k])%Mod,s%=Mod;
}
} return s%Mod;
} int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
Q=read();
while(Q--){
x1=read(),Y1=read(),x2=read(),y2=read(),k=read(); LL ans=0;
k--; if(k==-1) {puts("0"); continue;}
ans=(ans+calc(x2,y2,k)%Mod)%Mod;
//system("pause");
ans=(ans+calc(x1-1,Y1-1,k)%Mod)%Mod;
ans=(ans-calc(x2,Y1-1,k)+Mod)%Mod;
ans=(ans-calc(x1-1,y2,k)+Mod)%Mod;
printf("%lld\n",ans);
}
return 0;
}

[Codeforces-div.1 809C] Find a car的更多相关文章

  1. codeforces div.1 A

    A. Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input sta ...

  2. Codeforces div.2 B. The Child and Set

    题目例如以下: B. The Child and Set time limit per test 1 second memory limit per test 256 megabytes input ...

  3. codeforces泛做..

    前面说点什么.. 为了完成日常积累,傻逼呵呵的我决定来一发codeforces 挑水题 泛做.. 嗯对,就是泛做.. 主要就是把codeforces Div.1的ABCD都尝试一下吧0.0.. 挖坑0 ...

  4. [CF787D]遗产(Legacy)-线段树-优化Dijkstra(内含数据生成器)

    Problem 遗产 题目大意 给出一个带权有向图,有三种操作: 1.u->v添加一条权值为w的边 2.区间[l,r]->v添加权值为w的边 3.v->区间[l,r]添加权值为w的边 ...

  5. Congratulations, FYMS-OIers!

    Fuzhou Yan'an Middle School Online Judge 又一次上线啦! 真的是一波三折,主要功劳必须得属于精通网页编排.ubuntu 下如何使用 rm -rf 语句但是又能够 ...

  6. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  10. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

随机推荐

  1. 在使用ubuntu16.04+python3.5 下使用pip3出现pip3 error - '_NamespacePath' object has no attribute 'sort'

    使用pip3安装tensorflow以及gensim等时,出现如下错误: Traceback (most recent call last): File "/usr/local/bin/pi ...

  2. Eudyptula Challenge

    http://www.eudyptula-challenge.org/ The Eudyptula Challenge What is it? The Eudyptula Challenge is a ...

  3. 多线程伪共享FalseSharing

    1. 伪共享产生: 在SMP架构的系统中,每个CPU核心都有自己的cache,当多个线程在不同的核心上,并且某线程修改了在同一个cache line中的数据时,由于cache一致性原则,其他核心cac ...

  4. 内存分配器memblock【转】

    转自:http://blog.csdn.net/kickxxx/article/details/54710243 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 背景 Data ...

  5. pillow模块的学习

    https://github.com/wangbinyq/pillow_example http://pillow.readthedocs.org/en/latest/handbook/tutoria ...

  6. api文档工具

    平台选型         Apidoc         文档参考:http://apidocjs.com        优点      文档齐全,操作简单,ui清晰,代码注解查询性强,语言支持多元化, ...

  7. [hadoop][基本原理]zookeeper基本原理

    1.简介 https://www.ibm.com/developerworks/cn/opensource/os-cn-zookeeper/ 2. 数据模型 Zookeeper 会维护一个具有层次关系 ...

  8. 数字签名(以ActiveXDemo为例)

    1.创建Install.inf文件和run.bat Install.inf: [version] signature="$CHICAGO$" AdvancedINF=2.0 [Se ...

  9. visualvm监控远程机器上的Java程序

    源文:http://hanwangkun.iteye.com/blog/1195526

  10. linux命令(43):cal命令

    cal命令可以用来显示公历(阳历)日历.公历是现在国际通用的历法,又称格列历,通称阳历.“阳历”又名“太阳历”,系以地球绕行太阳一周为一年,为西方各国所通用,故又名“西历”. 1.命令格式: cal  ...