[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 ...
随机推荐
- 【HNOI】d 最小割
[题目大意]给定一个n*m的土地,每块可以种a或b作物,每种作物在不同的位置有不同的收成,同时,有q个子矩阵中,全部种指定的作物(a或b)会有一定的加成收成,求最大收成. [数据范围] 50% n,m ...
- Python标准库笔记(1) — string模块
String模块包含大量实用常量和类,以及一些过时的遗留功能,并还可用作字符串操作. 1. 常用方法 常用方法 描述 str.capitalize() 把字符串的首字母大写 str.center(wi ...
- TCP之connect
1. connect函数: #include <sys/socket.h> int connect(int sockfd, const struct sockaddr *servaddr, ...
- linux子系统的初始化_subsys_initcall()【转】
转自:http://my.oschina.net/u/572632/blog/305492 目录[-] 概述 section的声明 注册 调用 IN BUILDING 概述 内核选项的解析完成之后,各 ...
- [caffe error] undefined reference to `inflateValidate@ZLIB_1.2.9'
undefined reference to `inflateValidate@ZLIB_1.2.9' Makefile.config添加一行LINKFLAGS := -Wl,-rpath,$(HOM ...
- 【Java基础】重写equals需要重写hashcode
Object里的equals用来比较两个对象的相等性,一般情况下,当重写这个方法时,通常有必要也重写hashcode,以维护hashcode方法的常规协定,或者说这是JDK的规范,该协定声明相等对象必 ...
- 浮动的div无论窗口大小变化都能居中显示的js
当div是浮动的时候浏览器窗口发生变化的时候不能居中显示(因为浮动的时候一般设定的有left或者right值) 可以先用jquery获取外围的div随浏览器变化而变化的宽度(加上监听事件) 之后再获取 ...
- 简单搞懂OAuth2.0
本文转自:https://www.cnblogs.com/flashsun/p/7424071.html 原作者:闪客sun 一张图搞定OAuth2.0 目录 1.引言 2.OAuth2.0是什么 3 ...
- python 基础 习题
1.执行 Python 脚本的两种方式2.简述位.字节的关系 1Byte = 8bits 3.简述 ascii.unicode.utf-8.gbk 的关系 都是字符集,unicode兼容其他3种字符集 ...
- opencv 图像转换
#include <cv.h> #include <highgui.h> int main() { CvPoint2D32f srcTri[], dstTri[]; CvMat ...