[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 ...
随机推荐
- fragment+tabhost与viewpager
学到哪里写到哪里吧 A.viewpager a.用V4包中的fragment,activity继承FragmentActivity b.布局中加入<android.support.v4.view ...
- Perl6 Bailador框架(1):开始
use v6; use Bailador; get '/' => sub { '<h1><center>Hello, World</center></h ...
- 74cms 注入exp
遇到就瞎写了一个: #!/usr/bin/env python #encoding:utf-8 #by i3ekr import requests,optparse,re parse = optpar ...
- 【swupdate文档 二】许可证
许可证 SWUpdate是免费软件.它的版权属于Stefano Babic和其他许多贡献代码的人(详情请参阅实际源代码和git提交信息). 您可以根据自由软件基金会发布的GNU通用公共许可证第2版的条 ...
- Linux 入门记录:十八、Linux 系统启动流程 + 单用户修改 root 密码 + GRUB 加密
一.系统启动流程 一般来说,Linux 系统的启动流程是这样的: 1. 开机之后,位于计算机主板 ROM 芯片上的 BIOS 被最先读取,在进行硬件和内存的校验以及 CPU 的自检没有异常后, BIO ...
- go语言爬虫goquery和grequests的使用
/*下载工具*/ package main import ( "fmt" //go语言版本的jquery "github.com/PuerkitoBio/goquery& ...
- awk常见操作整理(更新)
awk的基本结构 awk 'BEGIN{} pattern {} END {}' #pattern {} 部分是针对每行进行循环处理的,有pattern表示对匹配到的行处理,没有pattern表示对所 ...
- POJ - 2478
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12802 Accepted: 4998 D ...
- Python Flask SQLALchemy基础知识
一.介绍 SQLAlchemy是一个基于Python实现的ORM框架.该框架建立在 DB API之上,使用关系对象映射进行数据库操作,简言之便是:将类和对象转换成SQL,然后使用数据API执行SQL并 ...
- Django基础之forms组件中的ModelForm组件
Django的model form组件 这是一个神奇的组件,通过名字我们可以看出来,这个组件的功能就是把model和form组合起来,先来一个简单的例子来看一下这个东西怎么用:比如我们的数据库中有这样 ...