题意:

求区间$[l,r]$内有多少有序数对$(a,b)$满足$a+b=a\bigoplus b$。

$l,r\leq 10^9$。

题解:

有用的就一句话:

求区间内一元组可以一维容斥,同理求二元组可以二维容斥,三元组可以三维容斥……

我tm原来居然不知道,佛了。

然后数位dp就完事了。

代码:

#include<bits/stdc++.h>
#define maxn 55
#define maxm 500005
#define inf 0x7fffffff
#define ll long long using namespace std;
ll dp[maxn][][][][],d1[maxn],d2[maxn]; inline ll read(){
ll x=,f=; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-;
for(;isdigit(c);c=getchar()) x=x*+c-'';
return x*f;
} inline ll dfs(ll now,int t1,int t2,int q1,int q2){
if(now==-) return ;
if(dp[now][t1][t2][q1][q2]!=-) return dp[now][t1][t2][q1][q2];
int u1=t1?d1[now]:,u2=t2?d2[now]:; ll res=;
for(int i=;i<=u1;i++)
for(int j=;j<=u2;j++){
if(i== && j==) continue;
int nt1=t1&&(i==u1);
int nt2=t2&&(j==u2);
int nq1=q1||(i==);
int nq2=q2||(j==);
res+=dfs(now-,nt1,nt2,nq1,nq2);
}
dp[now][t1][t2][q1][q2]=res;
return res;
} inline ll calc(ll x,ll y){
if(x< || y<) return ;
memset(dp,-,sizeof(dp));
for(ll i=;i<=;i++) d1[i]=((x>>i)&);
for(ll i=;i<=;i++) d2[i]=((y>>i)&);
return dfs(,,,,);
} int main(){
ll T=read();
while(T--){
ll l=read(),r=read();
printf("%I64d\n",calc(r,r)-*calc(l-,r)+calc(l-,l-));
}
return ;
}

F

[cf 1245 F] Daniel and Spring Cleaning的更多相关文章

  1. Codefroces 1245 F. Daniel and Spring Cleaning

    传送门 考虑简单的容斥 设 $F(n,m)$ 表示 $a \in [1,n] , b \in [1,m]$ 的满足 $a+b=a \text{ xor } b$ 的数对的数量 那么答案即为 $F(r, ...

  2. Codeforces Round #597 (Div. 2) F. Daniel and Spring Cleaning 数位dp

    F. Daniel and Spring Cleaning While doing some spring cleaning, Daniel found an old calculator that ...

  3. codeforces 597div2 F. Daniel and Spring Cleaning(数位dp+二维容斥)

    题目链接:https://codeforces.com/contest/1245/problem/F 题意:给定一个区间(L,R),a.b两个数都是属于区间内的数,求满足 a + b = a ^ b ...

  4. CF1245F: Daniel and Spring Cleaning

    CF1245F: Daniel and Spring Cleaning 题意描述: 给定区间\([L,R]\),其中 \((0\leq L,R\leq 10^9)\),问在区间内有多少数对\((x,y ...

  5. CodeForces - 1245F Daniel and Spring Cleaning (数位DP)

    While doing some spring cleaning, Daniel found an old calculator that he loves so much. However, it ...

  6. CF 633 F. The Chocolate Spree 树形dp

    题目链接 CF 633 F. The Chocolate Spree 题解 维护子数答案 子数直径 子数最远点 单子数最长直径 (最长的 最远点+一条链) 讨论转移 代码 #include<ve ...

  7. Good Bye 2015 F - New Year and Cleaning

    F - New Year and Cleaning 这题简直是丧心病狂折磨王.. 思路:容易想到这样一个转换,把整个矩形一起移动,矩形移出去的时候相当于一行或者一列. 为了优化找到下一个消去的点,我先 ...

  8. CF #271 F Ant colony 树

    题目链接:http://codeforces.com/contest/474/problem/F 一个数组,每一次询问一个区间中有多少个数字可以整除其他所有区间内的数字. 能够整除其他所有数字的数一定 ...

  9. CF 494 F. Abbreviation(动态规划)

    题目链接:[http://codeforces.com/contest/1003/problem/F] 题意:给出一个n字符串,这些字符串按顺序组成一个文本,字符串之间用空格隔开,文本的大小是字母+空 ...

随机推荐

  1. nginx之系统参数优化

    系统参数优化 默认的Linux内核参数考虑的是最通用场景,不符合用于支持高并发访问的Web服务器的定义,根据业务特点来进行调整,当Nginx作为静态web内容服务器.反向代理或者提供压缩服务器的服务器 ...

  2. nginx 反向代理配置示例

    Nginx反向代理在生产环境中使用很多的. 场景1: 域名没有备案,可以把域名解析到香港一台云主机上,在香港云主机做个代理,而网站数据是在大陆的服务器上. server { listen ; serv ...

  3. nginx.conf 配置解析之文件结构

    nginx.conf配置文件结构如下: ...... #主要定义nginx的全局配置 events{ #events(事件)块:主要配置网络连接相关 } http{ #http块:代理缓存和日志定义绝 ...

  4. GCC编译UDF和gdb调试UDF

    Fluent版本:19.0 前面我们介绍过使用VS来编译和调试UDF,其实我们也可以用GCC来编译UDF.gdb调试UDF.本次介绍的方法更具有通用性,也适用于Linux下Fluent的UDF编译和调 ...

  5. 欧拉法求解常微分方程(c++)

    #include<iostream> #include<iomanip> using namespace std; int main() { double x, y, h;   ...

  6. Java设计模式之builder模式

    Java设计模式之builder模式 今天学mybatis的时候,知道了SQLSessionFactory使用的是builder模式来生成的.再次整理一下什么是builder模式以及应用场景. 1. ...

  7. [Beta]Scrum Meeting#7

    github 本次会议项目由PM召开,时间为5月12日晚上10点45分 时长15分钟 任务表格 人员 昨日工作 下一步工作 木鬼 撰写博客整理文档 撰写博客整理文档 swoip 为适应新功能调整布局 ...

  8. adb server version (31) doesn't match this client (41); killing...

    1.有时候用adb工具去连接安卓设备,或者模拟器的时候,会提示adb server version(31) doesn’t match this client(41)这样的提示.如图 提示的字面意思就 ...

  9. Learning to Learn and Predict: A Meta-Learning Approach for Multi-Label Classification

    Learning to Learn and Predict: A Meta-Learning Approach for Multi-Label Classification 2019-10-01 11 ...

  10. MAC OS系统替换homebrew使用阿里云或中科大的镜像源

    阿里云镜像 # 替换brew.git: cd "$(brew --repo)" git remote set-url origin https://mirrors.aliyun.c ...