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}\) ,之前 ...
随机推荐
- STL源码剖析:配接器
启 配接器就是适配器 STL中的适配器一共三种: 迭代器适配器 是一种观念上的改变,如将赋值操作变成插入,前进变成后退,等 函数适配器 STL中最广泛的配接器群体 可以实现连续配接 配接操作:bind ...
- this指向面试题两则
面试题1 let len = 10; function fn() { console.info(this.len) } fn(); // A let Person = { len: 5, say: f ...
- Linux系统安装Samba共享服务器详解及安装配置
一.简介 Samba服务程序是一款基于SMB协议并由服务端和客户端组成的开源文件共享软件,实现了Linux和windows系统间的文件共享.SMB(Server Messages Block,信息服务 ...
- Fortify Audit Workbench 笔记索引
Password Management: Password in Configuration File(明文存储密码) https://www.cnblogs.com/mahongbiao/p/124 ...
- Python Cookbook(第3版) 中文版 pdf完整版|网盘下载内附提取码
Python Cookbook(第3版)中文版介绍了Python应用在各个领域中的一些使用技巧和方法,其主题涵盖了数据结构和算法,字符串和文本,数字.日期和时间,迭代器和生成器,文件和I/O,数据编码 ...
- SSM三大框架的整合
好好学习,天天向上 本文已收录至我的Github仓库DayDayUP:github.com/RobodLee/DayDayUP,欢迎Star,更多文章请前往:目录导航 在Java后端开发领域,Spri ...
- python3 openssl问题(贼有用)
目录 一.问题描述 二.排查过程 三.总结 四.写在最后 一.问题描述 在python3 执行任何的request请求时,都会报以下的错误,纵观全网,以下基本尝试过了,对于我这个是无效的,后来不知道怎 ...
- 15 张精美动图全面讲解 CORS
前言: 本文翻译自 Lydia Hallie 小姐姐写的
- 实验02——java两个数交换的三种解决方案
package cn.tedu.demo;/** * @author 赵瑞鑫 E-mail:1922250303@qq.com * @version 1.0* @创建时间:2020年7月16 ...
- JVM进行篇
结合字节码指令理解Java虚拟机栈和栈帧 栈帧:每个栈帧对应一个被调用的方法,可以理解为一个方法的 ...