传送门

题目:

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. Java继承多态

    一. 父类引用指向子类对象父类名(接口名) 对象名=new 子类(接口)名称() 二. 父子继承关系中,成员变量重名1.直接通过子类对象访问成员变量 =左边是谁,就优先用谁2.间接通过成员方法访问成员 ...

  2. office 2016激活方法windows

    安装office 2016 win+R,输入“cmd” 根据系统位数和安装的office位数选择相应的命令 OFFICE 64位 和 WINDOWS 64位 cscript "C:\Prog ...

  3. 如何用redis做缓存

    redis缓存 在互联网应用中经常需要用redis来缓存热点数据. redis数据在内存,可以保证数据读取的高效,接近每秒数十万次的吞吐量 减少下层持久层数据库读取压力,像mongodb,每秒近千次读 ...

  4. SpringBoot+Vue项目上手

    博客 https://gitee.com/RoadsideParty/White-Jotter-Vue?_from=gitee_search UI框架 https://at-ui.github.io/ ...

  5. php imap 那些坑

    今天调试php 接收邮件,遇见的几大坑! 第一,返回错误 关键字imap_open返回flase 原来{{$mailServer}:143}INBOX  的端口,不是根据outlook给的,,,,,是 ...

  6. 搭建vue项目的步骤

    新建vue脚手架 vue-element-cms步骤: 1. vue create ……………(文件名)---这里取为vue-element-cms 2. 命令行工具进入这个文件夹,安装路由依赖包 n ...

  7. linux 命令行 拯救萌新精简版

    装上linux 真机而不会命令行简直是太难了(这是什么人间疾苦) 于是,来几个非常基础的命令行,给(像我这样)的萌新们一点点前进的动力,也给奋斗在linux路上的大佬们一点点来自萌新的敬意吧. 一个非 ...

  8. SpringBoot学习之整合Druid的简单应用

    一.Druid介绍 Druid简介 Druid是目前Java语言中最好的数据库连接池之一.结合了 C3P0.DBCP 等 DB 池的优点,同时加入了日志监控.Druid 是一个分布式的.支持实时多维 ...

  9. bzoj 2225 [Spoj 2371]Another Longest Increasing

    这道题 连续上升的三元组 且已经按照第一维排好序了. 直接上CDQ分治即可 当然也是可以2-Dtree解决这个 问题 但是感觉nlog^2 比nsqrt(n)要快一些.. 算是复习一发CDQ分治吧 也 ...

  10. Spring Cloud Data Flow初体验,以Local模式运行

    1 前言 欢迎访问南瓜慢说 www.pkslow.com获取更多精彩文章! Spring Cloud Data Flow是什么,虽然已经出现一段时间了,但想必很多人不知道,因为在项目中很少有人用.不仅 ...