AtCoder ABC 129E Sum Equals Xor
题目链接:https://atcoder.jp/contests/abc129/tasks/abc129_e
题目大意
给定一个二进制表示的数 L,问有多少对自然数 (a, b) 满足 $a + b \leq L 且 a + b = a \oplus b $。
分析
- 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。
- 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的更多相关文章
- AtCoder ABC 242 题解
AtCoder ABC 242 题解 A T-shirt 排名前 \(A\) 可得 T-shirt 排名 \([A+1,B]\) 中随机选 \(C\) 个得 T-shirt 给出排名 \(X\) ,求 ...
- 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 ...
- [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 ...
- 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 ...
- Sum of xor
Sum of xor jdoj-2160 题目大意:给你一个n,求1^2^...^n. 注释:$n<=10^{18}$. 想法:第一道异或的题.先来介绍一下什么是异或.a^b表示分别将两个数变成 ...
- [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 ...
- [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 ...
- LeetCode - Subarray sum equals k
Given an array of integers and an integer k, you need to find the total number of continuous subarra ...
- 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 ...
随机推荐
- (补充)9.Struts2中的OGNL表达式
OGNL表达式概述 1. OGNL是Object Graphic Navigation Language(对象图导航语言)的缩写 * 所谓对象图,即以任意一个对象为根,通过OGNL可以访问与这个对象关 ...
- vue 单元素过渡
demo <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- FTP 连接模式 (主动模式被动模式)
FTP是有两种传输的模式的,主动模式和被动模式,一个完整的FTP文件传输需要建立两种类型的连接,一种为文件传输下命令,称为控制连接,另一种实现真正的文件传输,称为数据连接. 1. 控制连接客户端希望与 ...
- PHP rand() 函数
定义和用法 rand() 函数生成随机整数. 提示:如果您想要一个介于 10 和 100 之间(包括 10 和 100)的随机整数,请使用 rand (10,100). 提示:mt_rand() 函数 ...
- NX二次开发-创建直线UF_CURVE_create_line与NXOpen->CreateLine
NX11+VS2013 #include <uf.h> #include <uf_curve.h> #include <NXOpen/CurveCollection.hx ...
- Typora--终于找到一个能够解决将csdn文章同步到hexo的完美编辑器(解决csdn图片防盗链导致无法直接复制文章的问题)。
文章目录 需求 背景 新宠 告诉我,我的名字叫什么?大声点我听不见~ 页面 神奇之处 看得见的优点 如何设置项目根目录 如何显示图片? 于是最终操作流程 个人博客:https://mmmmmm.me ...
- idea不断提示=========>This file is indented with tabs instead of 4 spaces
file->other settings ->default settings
- postman中如何传数组
方法一: postman的传参: java接收: package com.nps.base.xue.xd.groovyEngine import com.google.gson.Gson import ...
- solr 启动报错Cannot load analyzer: org.wltea.analyzer.lucene.IKAnalyzer
schema.xml 配置文件信息: <field name="title" type="text_ik" indexed="true" ...
- java-day14
多线程程序访问共享数据会产生安全问题 解决线程安全问题 同步代码块 synchronized(锁对象){ 可能出现线程问题的代码 } 同步方法 修饰符 synchronized 返回值类型 方法名() ...