老年选手需要多写一些思维题qwq。

通过打表很容易发现对于(i,j),值为(i-1)^(j-1)+1,然后本题就没了qwq。

矩阵差分还是很容易想到的,容斥成四个矩阵。

然后看到异或很容易想到三件事:数位DP、字典树、线性基。很容易发现后两种与本题不符,就是数位DP了,从高位到低位DP,f[i][0/1][0/1][0/1]表示到第i位,当前的x、y、x^y是否达到上界,然后直接暴力枚举当前位即可。因为q<=1e4怕memset多了出事,我用了滚动数组qwq。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+,mod=1e9+;
int f[][][][],g[][][][];
void add(int&x,int y){x=x+y>=mod?x+y-mod:x+y;}
ll work(int n,int m,int k)
{
if(n<||m<)return ;
memset(f,,sizeof f),memset(g,,sizeof g);
int p=;
g[][][][]=;
for(int i=;~i;i--)
{
int x=n>>i&,y=m>>i&,z=k>>i&;
for(int j=;j<=;j++)
for(int k=;k<=;k++)
for(int l=;l<=;l++)
if(g[p^][j][k][l])
{
for(int X=;X<=(x|(!j));X++)
for(int Y=;Y<=(y|(!k));Y++)
if((X^Y)<=z||!l)
{
add(f[p][j&(X==x)][k&(Y==y)][l&((X^Y)==z)],(f[p^][j][k][l]+1ll*g[p^][j][k][l]*((X^Y)<<i)%mod)%mod);
add(g[p][j&(X==x)][k&(Y==y)][l&((X^Y)==z)],g[p^][j][k][l]);
}
f[p^][j][k][l]=g[p^][j][k][l]=;
}
p^=;
}
int ans=;
for(int j=;j<=;j++)
for(int k=;k<=;k++)
for(int l=;l<=;l++)
add(ans,(f[p^][j][k][l]+g[p^][j][k][l])%mod);
return ans;
}
int main()
{
int T;scanf("%d",&T);
while(T--)
{
int ax,ay,bx,by,k;scanf("%d%d%d%d%d",&ax,&ay,&bx,&by,&k);
ax--,ay--,bx--,by--,k--;
printf("%lld\n",((work(bx,by,k)-work(ax-,by,k)-work(bx,ay-,k)+work(ax-,ay-,k))%mod+mod)%mod);
}
}

CF809C(找规律+数位DP)的更多相关文章

  1. 找规律/数位DP HDOJ 4722 Good Numbers

    题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数 ...

  2. 2017年icpc西安网络赛 Maximum Flow (找规律+数位dp)

    题目 https://nanti.jisuanke.com/t/17118 题意 有n个点0,1,2...n-1,对于一个点对(i,j)满足i<j,那么连一条边,边权为i xor j,求0到n- ...

  3. Codeforces D. Little Elephant and Interval(思维找规律数位dp)

    题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...

  4. Codeforces Round #260 (Div. 2) A , B , C 标记,找规律 , dp

    A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  5. hdu 4722 Good Numbers 规律 数位dp

    #include<iostream> #include<cstring> #include<cstdio> #include<vector> #incl ...

  6. 剑指 Offer 44. 数字序列中某一位的数字 + 找规律 + 数位

    剑指 Offer 44. 数字序列中某一位的数字 Offer_44 题目描述 题解分析 java代码 package com.walegarrett.offer; /** * @Author Wale ...

  7. HDU - 4722 Good Numbers 【找规律 or 数位dp模板】

    If we sum up every digit of a number and the result can be exactly divided by 10, we say this number ...

  8. HDU 4588 Count The Carries 数位DP || 打表找规律

    2013年南京邀请赛的铜牌题...做的非常是伤心.另外有两个不太好想到的地方.. ..a 能够等于零,另外a到b的累加和比較大.大约在2^70左右. 首先说一下解题思路. 首先统计出每一位的1的个数, ...

  9. UVALive - 6575 Odd and Even Zeroes 数位dp+找规律

    题目链接: http://acm.hust.edu.cn/vjudge/problem/48419 Odd and Even Zeroes Time Limit: 3000MS 问题描述 In mat ...

随机推荐

  1. CF1209B Koala and Lights

    It is a holiday season, and Koala is decorating his house with cool lights! He owns n lights, all of ...

  2. vue使用Vant UI中的swiper组件及传值

    子组件SwiperBanner <!-- --> <template> <div class="swiper"> <van-swipe : ...

  3. springboot - 映射 HTTP Response Status Codes 到自定义 JSP Error 页面

    1.总览 2.代码 1).pom.xml <dependencies> <dependency> <groupId>org.springframework.boot ...

  4. Android之Intent相关知识

    什么是Intent?Intent的作用? Intent是一个消息传递对象,我们可以通过它来启动其他组件或者在组件之间传递数据. 通过Intent启动其他组件 Intent可以用来启动Activity, ...

  5. java floor,ceil和round方法

    Math.floor():返回值是double类型的,返回的是不大于它的最大整数 举例: double x = Math.floor(5.8); System.out.println(x); //输出 ...

  6. 安装双系统(win8+ubuntu16)

    一.参考网址 1.windows10安装ubuntu双系统教程(绝对史上最详细) 2.安装Windows+Ubuntu双系统 二.注意细节 1.怎么看自己电脑是MBR还是UEFI:win+r输入msi ...

  7. leetcode - 两数之和Ⅳ 输入BST(653)

    题目描述:给定一个二叉搜索树和一个目标结果,如果 BST 中存在两个元素且它们的和等于给定的目标结果,则返回 true. 解题思路:根据二叉搜索树的特点,对二叉搜索树进行中序遍历可以得到一个从小到达排 ...

  8. A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题

    ---恢复内容开始--- output standard output The final match of the Berland Football Cup has been held recent ...

  9. UVA - 10285 Longest Run on a Snowboard(最长的滑雪路径)(dp---记忆化搜索)

    题意:在一个R*C(R, C<=100)的整数矩阵上找一条高度严格递减的最长路.起点任意,但每次只能沿着上下左右4个方向之一走一格,并且不能走出矩阵外.矩阵中的数均为0~100. 分析:dp[x ...

  10. Sequence Models Week 1 Character level language model - Dinosaurus land

    Character level language model - Dinosaurus land Welcome to Dinosaurus Island! 65 million years ago, ...