[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 ...
随机推荐
- 抓其根本(一)(hdu2710 Max Factor 素数 最大公约数 最小公倍数.....)
素数判断: 一.根据素数定义,该数除了1和它本身以外不再有其他的因数. 详见代码. int prime() { ; i*i<=n; i++) { ) //不是素数 ; //返回1 } ; //是 ...
- querySelector()与querySelectorAll()
1.querySelector() 参数:css选择器 返回匹配指定css选择器元素的第一个子元素 2.querySelectorAll() 参数:css选择器 返回匹配指定css选择器的所有元素
- 【转】CVE-2010-4258 漏洞分析
一. 漏洞简介 CVE-2010-4258这个漏洞很有意思,主要思路是如果通过clone函数去创建进程,并且带有CLONE_CHILD_CLEARTID标志,那么进程在退出的时候,可以造成内核任意地址 ...
- 自动化测试===requests+unittest+postman的接口测试
postman是一个跨平台的接口测试工具,下载链接在这里:https://www.getpostman.com/ unittest是一个单元测试框架,python中安装:pip install uni ...
- 设计模式之笔记--适配器模式(Adapter)
适配器模式(Adapter) 定义 适配器模式(Adapter),将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以在一起工作. 适配器模式 ...
- 流程控制--for序列
In []: list1 = [,,,] In []: for i in list1: ...: print i ...: In []: for i in list1: print i, ...: / ...
- java 执行 class
run.sh: #!/bin/bash CLASSPATH=. for jar in *.jar; do CLASSPATH=$CLASSPATH:$jardone CACHE_FILE=`pwd`/ ...
- 判断ios当前的sdk版本的方法
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_6_0 // 当前支持的sdk版本是否低于6.0 //ios 6.0以下的处理 #else //io ...
- google code-prettify 代码高亮插件使用方法
找代码高亮插件选了好久,还是这个使用起来比较方便. 先上链接:插件下载地址 官方使用方法地址 建议看官方的资料,我这里仅仅简要描述一下使用方法: 引入方法: 测试引入是否成功:herf 换成 自己放置 ...
- Java 类、属性、方法修饰符 public、private、protected、default
Java 中修饰类修饰符:public .default (默认) Java 中修饰类中属性.方法修饰符:public.private.protected.default (默认) 通过 IDEA 创 ...