[cf 1245 F] Daniel and Spring Cleaning
题意:
求区间$[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的更多相关文章
- 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, ...
- 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 ...
- codeforces 597div2 F. Daniel and Spring Cleaning(数位dp+二维容斥)
题目链接:https://codeforces.com/contest/1245/problem/F 题意:给定一个区间(L,R),a.b两个数都是属于区间内的数,求满足 a + b = a ^ b ...
- CF1245F: Daniel and Spring Cleaning
CF1245F: Daniel and Spring Cleaning 题意描述: 给定区间\([L,R]\),其中 \((0\leq L,R\leq 10^9)\),问在区间内有多少数对\((x,y ...
- CodeForces - 1245F Daniel and Spring Cleaning (数位DP)
While doing some spring cleaning, Daniel found an old calculator that he loves so much. However, it ...
- CF 633 F. The Chocolate Spree 树形dp
题目链接 CF 633 F. The Chocolate Spree 题解 维护子数答案 子数直径 子数最远点 单子数最长直径 (最长的 最远点+一条链) 讨论转移 代码 #include<ve ...
- Good Bye 2015 F - New Year and Cleaning
F - New Year and Cleaning 这题简直是丧心病狂折磨王.. 思路:容易想到这样一个转换,把整个矩形一起移动,矩形移出去的时候相当于一行或者一列. 为了优化找到下一个消去的点,我先 ...
- CF #271 F Ant colony 树
题目链接:http://codeforces.com/contest/474/problem/F 一个数组,每一次询问一个区间中有多少个数字可以整除其他所有区间内的数字. 能够整除其他所有数字的数一定 ...
- CF 494 F. Abbreviation(动态规划)
题目链接:[http://codeforces.com/contest/1003/problem/F] 题意:给出一个n字符串,这些字符串按顺序组成一个文本,字符串之间用空格隔开,文本的大小是字母+空 ...
随机推荐
- Comet OJ - Contest #15 题解
传送门 \(A\) 咕咕 const int N=1005; int a[N],n,T; int main(){ for(scanf("%d",&T);T;--T){ sc ...
- pytest . class
#在当前测试类的开始与结束执行. setup_class teardown_class #在每个测试方法开始与结束执行. setup teardown #在每个测试方法开始与结束执行,与setup/t ...
- 苹果手机微信浏览器select标签选择完成之后页面不会自动回到原位
说明: html默认select选择框控件在IOS的浏览器中 是底部弹出下拉选择. 这样到时页面位置错位,选择结束后对应不少元素的点击事件不响应. 这样看起来问题不大,但是选择完成之后点击确定提交弹出 ...
- Java NIO Buffer中各种状态属性的含义
关于NIO Buffer中的3个重要状态属性的含义: postion, limit与capacity. public class NioTest { public static void main(S ...
- Navicat 12.x for MySQL最新版安装破解教程(附安装包和注册机,全网独家可用
title: "Navicat 12.x for MySQL最新版安装破解教程(附安装包和注册机,全网独家可用" categories: soft tags: soft autho ...
- ps 渐进式图片的技巧(支持jpg,gif,png)
https://www.zhangxinxu.com/wordpress/2013/01/progressive-jpeg-image-and-so-on/ CTRL + SHIFT + ALT + ...
- 简述 IntentFilter(意图过滤器)
1.什么是IntentFilter ? IntentFilter翻译成中文就是“意图过滤器”,主要用来过滤隐式意图.当用户进行一项操作的时候,Android系统会根据配置的 “意图过滤器” 来寻找可以 ...
- Kafka安装教程(详细过程)
安装前期准备: 1,准备三个节点(根据自己需求决定) 2,三个节点上安装好zookeeper(也可以使用kafka自带的zookeeper) 3,关闭防火墙 chkconfig iptables o ...
- kotlin基础 range
a = 1..10 //[1,10] b = 1 unitl 10 //[1,10)
- django orm 分页(paginator)取数据出现警告manage.py:1: UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list: <class 'sign.models.Guest'> QuerySet.
使用django的orm做分页(Paginator)时出现了下面的警告 In [19]: p=Paginator(guest_list,2) manage.py:1: UnorderedObjectL ...