[Codeforces-div.1 809C] Find a car
[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的更多相关文章
- codeforces div.1 A
A. Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input sta ...
- 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 ...
- codeforces泛做..
前面说点什么.. 为了完成日常积累,傻逼呵呵的我决定来一发codeforces 挑水题 泛做.. 嗯对,就是泛做.. 主要就是把codeforces Div.1的ABCD都尝试一下吧0.0.. 挖坑0 ...
- [CF787D]遗产(Legacy)-线段树-优化Dijkstra(内含数据生成器)
Problem 遗产 题目大意 给出一个带权有向图,有三种操作: 1.u->v添加一条权值为w的边 2.区间[l,r]->v添加权值为w的边 3.v->区间[l,r]添加权值为w的边 ...
- Congratulations, FYMS-OIers!
Fuzhou Yan'an Middle School Online Judge 又一次上线啦! 真的是一波三折,主要功劳必须得属于精通网页编排.ubuntu 下如何使用 rm -rf 语句但是又能够 ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
随机推荐
- input file 文件上传,js控制上传文件的大小和格式
文件上传一般是用jquery的uploadify,比较好用.后面会出文章介绍uploadify这个插件. 但是,有时候为了偷懒,直接就用input 的file进行文件和图片等的上传,input fil ...
- 移动端页面使用rem布局
阿里团队的高清布局方案代码 所谓高清方案就是根据设备屏幕的DPR(设备像素比,又称DPPX,比如dpr=2时,表示1个CSS像素由4个物理像素点组成) 动态设置 html 的font-size, 同时 ...
- Fiddler--的一些使用技巧
1.Filters请求与响应的会话过滤 请求会话列表中存在上百个请求,怎么过滤想要的,可以启用 Fiddler Filters强大的过滤机制,还可以依据正则来过滤,如: REGEX:(?insx). ...
- ORA-02291:parent key not found
Hibernate operation: Could not execute JDBC batch update; SQL [insert into dchnpricecarchancesource ...
- Laravel 项目上线的一些注意事项
1.应用生产环境 在 .env 文件里设置 APP_ENV=production 2.关闭调试模式 在 .env 文件中设置 APP_DEBUG = false 3.生成 APP_KEY 使用 Art ...
- python基础===8道基础知识题
本文转自微信公众号: 2018-03-12 leoxin 菜鸟学Python 原文地址:http://mp.weixin.qq.com/s/JJSDv5YJOZ9e3hn28zWIsQ NO.1 Py ...
- hardseed
hardseed https://github.com/yangyangwithgnu/hardseed
- 斯坦福开源无Bug的随机计算图Certigrad
斯坦福开源无Bug的随机计算图Certigrad https://news.cnblogs.com/n/573690/ ttps://github.com/dselsam/certigrad
- 【bzoj3786】星系探索
ETT模版题. 真正的Eular-Tour-Tree维护的是树的欧拉序. 由于各种原因,没人知道怎么维护欧拉序,所以我写的是个假的,维护dfs序的. 本质还是用Splay维护序列. 然后因为我常数太差 ...
- 【hihocoder】sam-2
原意是把sam那一堆做完…… 这题还是很sb的,$\sum{maxlen(s)-minlen(s)+1}$就是本质不同的子串数量 然后因为suffix link的性质,maxlen[fa[s]]=mi ...