传送门

题目:

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的更多相关文章

  1. 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])递 ...

  2. 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 ...

  3. Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences (bitmasks +dp )

    https://codeforces.com/contest/1330/problem/D 题目大意:给出一个限制 d 与模数 m ,求出可以构造出的满足条件的数组 a 的个数,需要满足以下条件:   ...

  4. Codeforces Round #631 (Div. 1) B. Dreamoon Likes Sequences 题解(思维+求贡献)

    题目链接 题目大意 让你构造一个严格单调上升的数组a满足\(1<=a_1<a_2<....a_n<=d\) 而且要使得这个数组的异或前缀和也满足严格单调上升,求有多少个满足条件 ...

  5. Dreamoon Likes Coloring 【CF 1329 A】

    传送门 思路:"Dreamoon will choose a number pipi from range [1,n−li+1](inclusive) and will paint all ...

  6. CF 1272F Two Bracket Sequences (括号dp)

    题目地址 洛谷CF1272F Solution 首先题目中有两个括号串 \(s\) 和 \(t\) ,考虑先设计两维表示 \(s\) 匹配到的位置和 \(t\) 匹配到的位置. 接着根据 括号dp的一 ...

  7. Codeforces 631 (Div. 2) C. Dreamoon Likes Coloring 思维or构造

    https://codeforces.com/contest/1330/problem/C 给n个格子染色,有m种颜色,要求最后的所以格子被染色,并且有m种颜色. 染色要求:每种颜色有一个值li,选择 ...

  8. Dreamoon Likes Coloring(模拟+构造)

    \(这题刚好撞到我的思路了,但是因为模拟......我看了几十遍测试数据....\) $首先当\sum_^m$小于n时一定无解 大于呢?那我们就要浪费一些区间(覆盖一些点,也就是多出来的点) 但是又不 ...

  9. Codeforces Round #631 (Div. 1) A-C

    在 \(\text{Div. 2/3}\) 混了一个多月后,四个号终于都上紫了,也没用理由不打 \(\text{Div. 1}\) 了.这是我人生中的第一场 \(\text{Div .1}\) ,之前 ...

随机推荐

  1. 设计模式:state模式

    核心: 把状态的判断逻辑转移到表示不同状态的一系列类当中,可以把复杂的判断逻辑简化 例子: class State //状态接口 { public: virtual void show() = 0; ...

  2. elementUI form表单验证不通过的原因

    <el-form :model="form" :rules="rules"> <el-form-item prop="input&q ...

  3. elementUI form表单验证不通过的三个原因

    <el-form :model="form" :rules="rules"> <el-form-item prop="input&q ...

  4. 程序员肺被切掉一块还得去加班... 再谈“工作996,生病ICU”

    如题,为什么要说再谈“工作996,生病ICU”,因为996问题早已不是一个新问题,在我最近刚出版的新书<SOD框架“企业级”应用数据架构实战>写作期间,爆发了一次程序员“起义”,出现了一个 ...

  5. Zookeeper ----- ZAB算法

    介绍 Zookeeper没有使用Paxos实现,而是使用ZAB(Zookeeper原子消息广播协议)作为数据一致性的核心算法. ZAB是一种专为Zookeeper设计的支持崩溃恢复的原子广播协议. Z ...

  6. git上传本地项目到gitlab

    <1>输入git config --global user.name "你的用户名" <2>输入git config --global user.email ...

  7. web自动化 -- HTMLreport(三)测试报告输出log日志

    一.需求痛点 1.HTMLreport没法看到log日志,经过封装的框架不可能走一步就print() 2. 希望可以在HTMLreport中输出log日志 3.痛点截图 二.解决办法 1.既然是HTM ...

  8. 【CVPR2020】Wavelet Integrated CNNs for Noise-Robust Image Classification

    深度学习中的下采样(max-pooing, average-pooling, strided-convolution)通常会有两个不足:破坏了目标的基本结构.放大随机噪声.上采样操作同样容易受到影响. ...

  9. ubuntu的docker安装

    安装docker 安装 介绍一下docker 的中央仓库们 Docker官方中央仓库: https://hub.docker.com/ 因为docker 网站在国外所以访问速度和你的运气有关还有网络. ...

  10. 17条嵌入式C语言编程小知识总结

    流水线被指令填满时才能发挥最大效能,即每时钟周期完成一条指令的执行(仅指单周期指令). 如果程序发生跳转,流水线会被清空,这将需要几个时钟才能使流水线再次填满.因此,尽量少的使用跳转指令可以提高程序执 ...