题目链接:https://atcoder.jp/contests/abc129/tasks/abc129_e

题目大意

  给定一个二进制表示的数 L,问有多少对自然数 (a, b) 满足 $a + b \leq L 且 a + b = a \oplus b $。

分析

  由于异或是无进位相加,所以 $a + b = a \oplus b $ 等价于 a 和 b 的每一位对应二进制位都不会是两个 1。
  设 L 有 n 个 1。按 L 中的顺序编号为 n~1。
  设 L(i) 为编号为 i 的 1 到 L 末尾所形成的子串。
  设 Ans(i) 为 L(i) 包含的自然数对数。
  a + b 有以下两种情况:
  1. a + b 的最高位和 L(i) 的最高位一样都是 1:那么 a 和 b 在 i 号 1 和 i + 1 号 1 之间的对应位置上必然全为 0,因此答案取决于 Ans(i - 1),而由于 a 和 b 可以互换,因此这部分贡献为 2 * Ans(i - 1),为方便计算可设 Ans(0) = 1。
  2. a + b 的最高位是 0 (相对于 L(i) 的最高位):那么 a 和 b 剩下的二进制位就没有限制了,每个 a, b 的二进制位都可以有 (0, 0), (0, 1), (1, 0) 三种情况,因此,总贡献为 $3^{L(i).size() - 1}$。

代码如下

 #include <bits/stdc++.h>
using namespace std; #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define UNIQUE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define REMOVE(x, c) x.erase(remove(x.begin(), x.end(), c), x.end()); // 删去 x 中所有 c
#define TOLOWER(x) transform(x.begin(), x.end(), x.begin(),::tolower);
#define TOUPPER(x) transform(x.begin(), x.end(), x.begin(),::toupper); #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} inline int gc(){
static const int BUF = 1e7;
static char buf[BUF], *bg = buf + BUF, *ed = bg; if(bg == ed) fread(bg = buf, , BUF, stdin);
return *bg++;
} inline int ri(){
int x = , f = , c = gc();
for(; c<||c>; f = c=='-'?-:f, c=gc());
for(; c>&&c<; x = x* + c - , c=gc());
return x*f;
} template<class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
} inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
} //min <= aim <= max
template<typename T>
inline bool BETWEEN(const T aim, const T min, const T max) {
return min <= aim && aim <= max;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef pair< int, PII > PIPII;
typedef pair< string, int > PSI;
typedef pair< int, PSI > PIPSI;
typedef set< int > SI;
typedef set< PII > SPII;
typedef vector< int > VI;
typedef vector< double > VD;
typedef vector< VI > VVI;
typedef vector< SI > VSI;
typedef vector< PII > VPII;
typedef map< int, int > MII;
typedef map< int, string > MIS;
typedef map< int, PII > MIPII;
typedef map< PII, int > MPIII;
typedef map< string, int > MSI;
typedef map< string, string > MSS;
typedef map< PII, string > MPIIS;
typedef map< PII, PII > MPIIPII;
typedef multimap< int, int > MMII;
typedef multimap< string, int > MMSI;
//typedef unordered_map< int, int > uMII;
typedef pair< LL, LL > PLL;
typedef vector< LL > VL;
typedef vector< VL > VVL;
typedef priority_queue< int > PQIMax;
typedef priority_queue< int, VI, greater< int > > PQIMin;
const double EPS = 1e-;
const LL inf = 0x7fffffff;
const LL infLL = 0x7fffffffffffffffLL;
const LL mod = 1e9 + ;
const int maxN = 1e5 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; string L;
LL ans = ; void mul_mod(LL &x, LL y) {
x = (x * y) % mod;
} void add_mod(LL &x, LL y) {
x = (x + y) % mod;
} LL pow_mod(LL x, LL y) {
LL ret = ;
while(y) {
if(y & ) mul_mod(ret, x);
mul_mod(x, x);
y >>= ;
}
return ret;
} int main(){
//freopen("MyOutput.txt","w",stdout);
//freopen("input.txt","r",stdin);
//INIT();
cin >> L;
rFor(i, L.size() - , ) {
if(L[i] == '') {
mul_mod(ans, );
add_mod(ans, pow_mod(, L.size() - i - ));
}
}
cout << ans << endl;
return ;
}

AtCoder ABC 129E Sum Equals Xor的更多相关文章

  1. AtCoder ABC 242 题解

    AtCoder ABC 242 题解 A T-shirt 排名前 \(A\) 可得 T-shirt 排名 \([A+1,B]\) 中随机选 \(C\) 个得 T-shirt 给出排名 \(X\) ,求 ...

  2. Subarray Sum & Maximum Size Subarray Sum Equals K

    Subarray Sum Given an integer array, find a subarray where the sum of numbers is zero. Your code sho ...

  3. [leetcode-560-Subarray Sum Equals K]

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  4. LeetCode 560. Subarray Sum Equals K (子数组之和等于K)

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  5. Sum of xor

    Sum of xor jdoj-2160 题目大意:给你一个n,求1^2^...^n. 注释:$n<=10^{18}$. 想法:第一道异或的题.先来介绍一下什么是异或.a^b表示分别将两个数变成 ...

  6. [LeetCode] Subarray Sum Equals K 子数组和为K

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  7. [Swift]LeetCode560. 和为K的子数组 | Subarray Sum Equals K

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  8. LeetCode - Subarray sum equals k

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  9. 560. Subarray Sum Equals K 求和为k的子数组个数

    [抄题]: Given an array of integers and an integer k, you need to find the total number of continuous s ...

随机推荐

  1. 处理Codeigniter CLI模式无法读取通过Apache写入的文件缓存

    运行环境: Ubuntu 16.04 + PHP 5.6.40 + Apache/2.4.18 Codeigniter: 3.1.10 Codeigniter 3.1.10,缓存驱动方式是文件方式 遇 ...

  2. 《DNS攻击防范科普系列3》 -如何保障 DNS 操作安全

    引言 前两讲我们介绍了 DNS 相关的攻击类型,以及针对 DDoS 攻击的防范措施.这些都是更底层的知识,有同学就来问能否讲讲和我们的日常操作相关的知识点,今天我们就来说说和我们日常 DNS 操作相关 ...

  3. QueryList 内容过滤

    <?php require 'vendor/autoload.php'; use QL\QueryList; $html =<<<STR <div id="de ...

  4. delphi 获取所有窗口标题

    unit Unit1; interface usesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ...

  5. NX二次开发-UFUN新建工程图UF_DRAW_create_drawing

    NX9+VS2012 #include <uf.h> #include <uf_draw.h> #include <uf_part.h> UF_initialize ...

  6. Java-javaFx库运用-自动弹跳的球

    (1)定义一个名为BallPane的类,用于显示一个弹动的球: (2)定义一个名为BounceBallControl的类,用来使用鼠标动作控制弹球,当鼠标按下的时候动画暂停,当鼠标释放的时候动画恢复执 ...

  7. Api:temple

    ylbtech-Api: 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbtech.cnb ...

  8. IntelliJ IDEA 创建的文件自动生成 Author 注释 签名

    IntelliJ IDEA 创建的文件自动生成 Author 注释 签名1.打开 File --> Setting2.找到 Editor --> File and Code Templat ...

  9. 引入css文件时,css link和@import区别

    这里link与@import介绍的是html引入css的语法单词.两者均是引入css到html的单词. 一.了解基本 1.link语法结构 <link href="CSSurl路径&q ...

  10. 深夜Python - 第1夜 - for 迷 in 迷思

    深夜Python - 第1夜 - for 迷 in 迷思 在一个月黑风高的夜晚,我悄悄打开编辑器,进入程序的世界.刚刚学会Python的我,由于一段时间的过度装B,被委托优化一段程序,我信心十足地接下 ...