CF 1329B Dreamoon Likes Sequences
题目:
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d,m find the number of arrays a, satisfying the following constraints:
- The length of a is n, n≥1
- 1≤a1<a2<⋯<an≤d
- Define an array b of length n as follows: b1=a1, ∀i>1,bi=bi−1⊕ai, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b1<b2<⋯<bn−1<bn should hold.
Since the number of possible arrays may be too large, you need to find the answer modulo m.
思路:容易想到如果两个数二进制的最高位都是1,则两者"^"后者数值一定比前者小,可以推断出"2^0 ~ 2^1 - 1","2^1 ~ 2^2 - 1",...,"2^(n-1) ~ 2^(n) - 1"为不同集合,我们只需要统计出每个集合的个数,然后求出组合方案数就行。
#include<iostream>
#include<string>
#include<vector>
#include<cstdio> #define ll long long
#define pb push_back using namespace std; const int N = 1e6 + ;
vector<ll > a;
ll p[N];
ll ans, MOD; void init()
{
int x = ;
while(){
p[x] = ( << x) - ;
if(p[x] > 1e9) break;
x++;
}
} void solve()
{ init(); int T;
cin >> T;
while(T--){ ans = ;
a.clear(); ll n;
cin >> n >> MOD; int inx = -;
for(int i = ; i < ; ++i){
if(n >= p[i]) a.pb(p[i] - p[i - ]);
else{
inx = i;
break;
}
} if(n - p[inx - ] > ) a.pb(n - p[inx - ]);
for(auto x : a){
ans = (ans * (x + )) % MOD;
} ans = (ans - + MOD) % MOD; //cout << "(ans = " << ans << ")" << endl;
cout << ans << endl;
}
} int main() { ios::sync_with_stdio(false);
cin.tie();
cout.tie();
solve();
//cout << "ok" << endl;
return ;
}
CF 1329B Dreamoon Likes Sequences的更多相关文章
- Codeforces Round #631 (Div. 2) D.Dreamoon Likes Sequences
题目连接:Dreamoon Likes Sequences 题意:给你d和m,让你构造一个递增数组a,使数组b(i==1,b[i]=a[i] ; i>1, b[i]=b[i-1]^a[i])递 ...
- Codeforces 631 (Div. 2) D. Dreamoon Likes Sequences 位运算^ 组合数 递推
https://codeforces.com/contest/1330/problem/D 给出d,m, 找到一个a数组,满足以下要求: a数组的长度为n,n≥1; 1≤a1<a2<⋯&l ...
- Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences (bitmasks +dp )
https://codeforces.com/contest/1330/problem/D 题目大意:给出一个限制 d 与模数 m ,求出可以构造出的满足条件的数组 a 的个数,需要满足以下条件: ...
- Codeforces Round #631 (Div. 1) B. Dreamoon Likes Sequences 题解(思维+求贡献)
题目链接 题目大意 让你构造一个严格单调上升的数组a满足\(1<=a_1<a_2<....a_n<=d\) 而且要使得这个数组的异或前缀和也满足严格单调上升,求有多少个满足条件 ...
- Dreamoon Likes Coloring 【CF 1329 A】
传送门 思路:"Dreamoon will choose a number pipi from range [1,n−li+1](inclusive) and will paint all ...
- CF 1272F Two Bracket Sequences (括号dp)
题目地址 洛谷CF1272F Solution 首先题目中有两个括号串 \(s\) 和 \(t\) ,考虑先设计两维表示 \(s\) 匹配到的位置和 \(t\) 匹配到的位置. 接着根据 括号dp的一 ...
- Codeforces 631 (Div. 2) C. Dreamoon Likes Coloring 思维or构造
https://codeforces.com/contest/1330/problem/C 给n个格子染色,有m种颜色,要求最后的所以格子被染色,并且有m种颜色. 染色要求:每种颜色有一个值li,选择 ...
- Dreamoon Likes Coloring(模拟+构造)
\(这题刚好撞到我的思路了,但是因为模拟......我看了几十遍测试数据....\) $首先当\sum_^m$小于n时一定无解 大于呢?那我们就要浪费一些区间(覆盖一些点,也就是多出来的点) 但是又不 ...
- Codeforces Round #631 (Div. 1) A-C
在 \(\text{Div. 2/3}\) 混了一个多月后,四个号终于都上紫了,也没用理由不打 \(\text{Div. 1}\) 了.这是我人生中的第一场 \(\text{Div .1}\) ,之前 ...
随机推荐
- Git报错问题集锦
git merge合并时遇上refusing to merge unrelated histories的解决方案 如果git merge合并的时候出现refusing to merge unrelat ...
- Springboot(二)springboot之jsp支持
参考恒宇少年的博客:https://www.jianshu.com/p/90a84c814d0c springboot内部对jsp的支持并不是特别理想,而springboot推荐的视图是Thymele ...
- PHP入门之类型与运算符(一)
前言 PHP对于大部分人来说,是比较容易入门的.笔者也是刚学习不久,所以就把自己学习的基础知识进行总结和整理.第一部分是类型与运算符.如果你想学习PHP,可以参考PHP学习手册学习,任何一本教学资料也 ...
- minSdkVersion、targetSdkVersion、compileSdkVersion三者的作用解析
1. minSdkVersion minSdkVersion限制安装application所需要的系统最低版本,低于该版本的系统都不可以安装该application.同时不能使用该level版本SDK ...
- 01_Linux基础篇
学于黑马.传智播客.尚硅谷 感谢 黑马官网 传智播客官网 尚硅谷官网 微信搜索"艺术行者",关注并回复关键词"linux"获取视频和教程资料! b站在线视频 第 ...
- PHP curl_strerror函数
(PHP 5 >= 5.5.0) curl_strerror — 返回错误码的描述. 说明 string curl_strerror ( int $errornum ) 返回错误码的文本描述信息 ...
- [草稿]Skill 中的map
https://www.cnblogs.com/yeungchie/ Skill 中的map map mapc mapcan mapcar mapcon mapinto maplist
- C/C++编程笔记:C++入门知识丨从结构到类的演变
先来看看本节知识的结构图吧! 接下来我们就逐步来看一下所有的知识点: 结构的演化 C++中的类是从结构演变而来的, 所以我们可以称C++为”带类的C”. 结构发生质的演变 C++结构中可以定义函数, ...
- CF R630 div2 1332 E Height All the Same
LINK:Height All the Same 比赛的时候 被这道题给打自闭了 还有1个多小时的时候开始想 想了30min 无果 放弃治疗. 心态炸了 F不想看了 应该要把题目全看一遍的 下次不能这 ...
- 实战:docker搭建FastDFS文件系统并集成SpringBoot
实战:docker搭建FastDFS文件系统并集成SpringBoot 前言 15年的时候,那时候云存储还远远没有现在使用的这么广泛,归根结底就是成本和安全问题,记得那时候我待的公司是做建站开发的,前 ...