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}\) ,之前 ...
随机推荐
- Hadoop之HDFS常用文件操作命令
命令基本格式:hadoop fs -cmd < args > 1. ls 列出hdfs文件系统根目录下的目录和文件hadoop fs -ls /dirhadoop fs -ls -R /d ...
- 3c数码商城
目标:2020样卷 已完成:增删改查 未完成:有些小知识点不在意丢失,因此导致有些未完善 解决方案:写代码时不要走心,专心一点,减少失误,减少时间,增加效率,使自己的项目看起来更优秀,注意小知识的掌握 ...
- 老男孩武老师的Django笔记
武老师的 Django 博客笔记 基础篇 https://www.cnblogs.com/wupeiqi/articles/5237704.html 进阶篇 https://www.cnblogs.c ...
- Python无限循环
Python 无限循环:在 while 循环语句中,可以通过让判断条件一直达不到 False ,实现无限循环. 条件表达式: # var = 1 # while var == 1: # 表达式永远为 ...
- Django学习路33_url 地址及删除元素 delete() 和重定向 return redirect('路径')
保存日期 def create(request): '''新增一本图书''' # 1.创建BookInfo对象 b = BookInfo() b.btitle = '流星蝴蝶剑' b.bpub_d ...
- PHP fseek() 函数
定义和用法 fseek() 函数在打开的文件中定位. 该函数把文件指针从当前位置向前或向后移动到新的位置,新位置从文件头开始以字节数度量. 如果成功该函数返回 0,如果失败则返回 -1.请注意,移动到 ...
- PHP symlink() 函数
定义和用法 symlink() 函数创建一个从指定名称连接的现存目标文件开始的符号连接. 如果成功,该函数返回 TRUE.如果失败,则返回 FALSE. 语法 symlink(target,link) ...
- PHP tanh() 函数
实例 返回不同数的双曲正切: <?php高佣联盟 www.cgewang.comecho(tanh(M_PI_4) . "<br>");echo(tanh(0.5 ...
- PHP money_format() 函数
实例 en_US 国际格式: <?php高佣联盟 www.cgewang.com$number = 1234.56;setlocale(LC_MONETARY,"en_US" ...
- Skill 脚本演示 ycAutoSnap.skl
https://www.cnblogs.com/yeungchie/ ycAutoSnap.skl 版图编辑中自动吸附 Path 的 "垂直线头",也可以批量对齐 Bus 走线,也 ...