\(>Codeforces \space 551 D. GukiZ and Binary Operations<\) 题目大意 :给出 \(n, \ k\) 求有多少个长度为 \(n\) 的序列 \(a\) 满足 \((a_1\ and \ a_2)or(a_2\ and \ a_3)or..or(a_{n-1}\ and \ a_n) = k\) 且 \(a_i \leq k \leq 2^l\) 并输出方案数在$\mod m $ 意义下的值 \(0≤ n ≤ 10^{18},\ 0 ≤ k…
Problem D. GukiZ and Binary Operations Solution 一位一位考虑,就是求一个二进制序列有连续的1的种类数和没有连续的1的种类数. 没有连续的1的二进制序列的数目满足f[i]=f[i-1]+f[i-2],恰好是斐波那契数列. 数据范围在10^18,用矩阵加速计算,有连续的1的数目就用2^n-f[n+1] 最后枚举k的每一位,是1乘上2^n-f[n+1],是0乘上f[n+1] 注意以上需要满足 2^l>k.并且这里l的最大值为64,需要特判. #inclu…
D. GukiZ and Binary Operations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We all know that GukiZ often plays with arrays. Now he is thinking about this problem: how many arrays a, of l…
D. GukiZ and Binary Operations   We all know that GukiZ often plays with arrays. Now he is thinking about this problem: how many arrays a, of length n, with non-negative elements strictly less then 2l meet the following condition: ? Here operation  m…
题目地址:http://codeforces.com/contest/551/problem/D 分析下公式能够知道,相当于每一位上放0或者1使得最后成为0或者1.假设最后是0的话,那么全部相邻位一定不能全是1,由于假设有一对相邻位全为1,那么这两个的AND值为1.又由于OR值是仅仅要有1.结果就为1.所以这位结果肯定为1.所以就推出了一个dp转移方程.dp[i][j]表示第i位上的数为j时的总个数.那么有: dp[i][0]=dp[i-1][0]+dp[i-1][1]; dp[i][1]=dp…
得到k二进制后,对每一位可取得的方法进行相乘即可,k的二进制形式每一位又分为2种0,1,0时,a数组必定要为一长为n的01串,且串中不出现连续的11,1时与前述情况是相反的. 且0时其方法总数为f(n) = f(n-1) + f(n-2),其中f(2) = 3,f(1) = 3. #include <bits/stdc++.h> using namespace std; #define ll long long ll n,k; int l,m; unsigned ]; queue<int…
大意: 给定$n,k,l,m$, 求有多少个长度为$n$, 元素全部严格小于$2^l$, 且满足 的序列. 刚开始想着暴力枚举当前or和上一个数二进制中$1$的分布, 但这样状态数是$O(64^3)$在加上矩阵幂的复杂度显然不行. 看了题解发现可以按每位单独来考虑. #include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include <math.h…
--睡太晚了. ..脑子就傻了-- 这个题想的时候并没有想到该这样-- 题意大概是有n堆箱子从左往右依次排列,每堆ai个箱子,有m个人,最開始都站在第一个箱子的左边, 每个人在每一秒钟都必须做出两种选择中的一种:1若他的位置有箱子则搬走一个箱子,2往右走一步. 问把全部箱子都搞掉的最少时间-- 非常显然二分一下答案,若为x秒,则每一个人都有x秒.一个一个排出去搬.看是否可以搬完-- 我居然没想到-- #include<map> #include<string> #include&l…
E - GukiZ and GukiZiana 思路:分块, 块内二分 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //#define mp m…
[codeforces 339]D. Xenia and Bit Operations 试题描述 Xenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1, a2, ..., a2n. Xenia is currently studying bit operations. To better understand how they work, Xenia decided t…
Binary Operations Time Limit: 2000 ms Memory Limit: 65535 kB Solved: 56 Tried: 674   Description   Bob has a sequence of N integers. They are so attractive, that Alice begs to have a continued part of it(a continued part here also means a continued s…
题目传送门 题意:所有连续的子序列的三种位运算计算后的值的和的期望分别是多少 分析:因为所有连续子序列的组数有n * (n + 1) / 2种,所以要将他们分类降低复杂度,以ai为结尾的分成一组,至于具体的做法,我觉得这篇题解已经写的很详细了,UESTC 1709 Binary Operations 吐槽一下,题解的代码交上去是TLE的,至今不知道为何,我写的是WA,将所有类型改成ll才AC... /************************************************…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way. In total there are n piles of…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare…
B. Quasi Binary Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/problem/B Description A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — ar…
https://codeforces.com/contest/551/problem/E 分块真强. 题意就是1.区间加,2.询问整个区间中,最远的两个x的距离. 分块,然后,每次找位子用二分找即可. #include <algorithm> #include <iterator> #include <iostream> #include <cstring> #include <cstdlib> #include <iomanip>…
Codeforces 339 D 题意:给定\(2^n​\)个数字,现在把它们进行如下操作: 相邻的两个数取\(or\) 相邻的两个数取\(xor\) 以此类推,直到剩下一个数. 问每次修改一个数字,最后得到的那个数是多少. 思路:线段树. 但是在\(pushup\)的过程中要看当前节点到底层的叶子距离有多长, 如果是奇数就\(or\),否则\(xor\). 单点修改,查询根即可.…
洛谷 Codeforces 思路 看到计数和\(998244353\),可以感觉到这是一个DP+生成函数+NTT的题. 设\(s_i\)表示\(i\)是否在集合中,\(A\)为\(s\)的生成函数,即\(A(x)=\sum_n s_nx^n\). 设\(f_n\)为有\(n\)分时二叉树的个数. 考虑枚举左子树大小和根节点权值,得到 \[ f_n=[n=0]+\sum_{i=1}^{mx} s_i \sum_{j=0}^{n-i} f_jf_{n-i-j} \] 然后记\(F(x)\)为\(f\…
题目传送门 传送点I 传送点II 传送点III 题目大意 每个点的权值$c\in {c_{1}, c_{2}, \cdots, c_{n}}$,问对于每个$1\leqslant s\leqslant m$有多少种不同的这样的有根二叉树满足所有点的点权和等于$s$. 先考虑一下怎么用dp来做. 设$f_{n}$表示点权和为$n$的满足条件的二叉树的个数,那么有: $f_{n} = \sum_{c \in C}\sum_{i = 0}^{n - c}f_{i}f_{n - c - i}$ 初值满足$…
E - Vasya and Binary String 思路:区间dp + 记忆化搜索 转移方程看上一篇博客. 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define y1 y11 #define pi acos(-1.0)…
A. Maximal Binary Matrix time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that th…
https://www.codewars.com/kata/binary-operations-number-1/train/csharp Your work is to write a method that takes a value and an index, and returns the value with the bit at given index flipped. The bits are numbered from the least significant bit (ind…
Professor GukiZ and Two Arrays 题解: 将a数组都sort一遍之后, b数组也sort一遍之后. 可以观察得到 对于每一个ai来说, 整个数组bi是一个V型的. 并且对于ai+1的最优解一定是在ai的右边. 然后我们将a数组 和 b数组枚举一遍. 然后再将a数组22组合, b数组22组合之后, 再枚举一遍. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_i…
题目链接:http://codeforces.com/contest/1204/problem/D2 题目是给定一个01字符串,让你尽可能多地改变1变为0,但是要保证新的字符串,对任意的L,R使得Sl,Sl+1,Sl+2...Sr的最长不递减子序列长度保持不变,求新的串s. dp思路,从前往后遍历串s. 1 . 遇到s[ i ] = 0 是不能改变的,因为从i到n的最长不递减子序列必定是以s[ i ] = 0为起点的,改变之后会减少长度. 2 . 遇到s[ i ] = 1.我们考虑如果变为0,首…
水题 #include<cstdio> #include<cstring> #include<cmath> #include<stack> #include<vector> #include<string> #include<iostream> #include<algorithm> using namespace std; int sx,sy; int ex,ey; int main() { scanf(&q…
原文链接www.cnblogs.com/zhouzhendong/p/CF438E.html 前言 没做过多项式题,来一道入门题试试刀. 题解 设 $a_i$ 表示节点权值和为 $i$ 的二叉树个数,特别的,我们定义 $a_0 = 1$ ,即我们认为没有节点也算一种二叉树. 设 $$g(x) = \sum_{i=1}^n x^{c_i}\\f(x) = \sum_{i=0}^{\infty} a_i x^i$$ 根据组合意义可得 $$f^2(x) g(x) + 1 = f(x) $$ 于是 $$…
#include <bits/stdc++.h> using namespace std; + ; const long long inf = 1e18; int n, m; long long suma, sumb; int a[maxn], b[maxn]; long long dbl_a[maxn], dbl_b[maxn]; ], sum_dbl_b[maxn * maxn + ]; int main() { map<int, int> pos_a; scanf("…
这个题目属于线段树的点更新区间查询,而且查的是整个区间,其实不用写query()函数,只需要输出根节点保存的值就可以了. 题意: 输入n,m表示有2^n个数和m个更新,每次更新只把p位置的值改成b,然后输出整个序列运算后的值,而这个运算就比较复杂了, 最下面一层两个数字之间或运算得到原来数目一半的数字,然后两个之间异或运算,得到一半,再或再异或------,一直到得到一个数字,这个数字就是要求的结果. 思路: 如果只是一种运算,这就是简单的线段树点更新,区间查询.而现在,我们要确定什么时候用or…
题目传送门 传送门 群除我均会猜结论/找规律,sad.... 以下内容只保证代码能过system test,证明应该都是在纯口胡 约定下文中的$LIS$表示最长不下降子序列. 定义$zero(s)$表示串$s$中0的个数,$one(s)$表示$s$中1的个数. 约定字符串的下标从1开始.$s_{l, r}$表示$s$的$l$个字符开始到第$r$个字符组成的子串. 定义一个串$s$是fixed string,当且仅当满足下面任意一个条件: $s$是一个空串 $s = 1t0$, 并且$t$是一个f…
D. GukiZ and Binary Operations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We all know that GukiZ often plays with arrays. Now he is thinking about this problem: how many arrays a, of l…