题目链接 题目大意 给你一个长为n的数组a,要你构造一个非严格单调上升的数组b和一个非严格单调下降的数组c,使得\(b_i+c_i=a_i\) 要你使这两个数组b,c中最大的元素最小,还有q次修改(q<=1e5),每次修改使[l,r]上的所有元素加x.在线查询 题目思路 看到这个区间操作,在线查询,就能想到线段树qwq,结果居然是差分 假设现在已经确定了\(b[1]\)\(c[1]\). 假设\(a[2]\)大于\(a[1]\)而\(b[2]+c[2]=a[2]\) 显然是想要b数组的每一个元素…
题目传送门 /* 数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了 另外不足一个区间的直接计算个数就可以了 */ #include <cstdio> #include <cmath> #include <iostream> #include <algorithm> #include <cstring> using namespace std; typedef unsigned long long ull; int…
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Equation 题目大意:有一个数字n,让你给出任意两个合数a,b满足a - b = n. 我们知道大于2的偶数都是合数,那么如果n为奇数,只要n加上一个奇数合数一定也为合数,如果n为偶数,那么n加上一个偶数合数也一定为合数. 因为只求任意一组,就直接选择4,9,若为奇数输出 +n 和9,偶数输出 +…
Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Description Input Output Sample Input 51 2 1 2 1 Sample Output 1 1 1 2 2 题解:这个题有做慢了,这种题做慢了和没做出来区别不大... 读题的时候脑子里还意识到素数除了2都是奇数,读完之后就脑子里就只剩欧拉筛了,贪心地构造使得前缀和是连续的素数,那…
B. Making Sequences is Fun time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For exampl…
题目:http://codeforces.com/problemset/problem/264/B 题意:给你一个递增序列,然后找出满足两点要求的最长子序列 第一点是a[i]>a[i-1] 第二点 gcd(a[i],a[i-1])>1 也就是说两个数不能互质 找出最长的子序列长度 思路:首先想互质问题,如果两个数互质说明两个数之间没有素因子相同,我们想以每个素因子结尾的最大长度是多少 然后比如样例 2 3 4 6 9 第一个数 2      2结尾 1 第二个数 3      3结尾 1 第三…
题目链接: http://codeforces.com/contest/900/problem/D 题意: 给你 \(x\) 和 \(y\),让你求同时满足这两个条件的序列的个数: \(a_1, a_2, ..., a_n (1 ≤ a_i)\). $ 1.$ $gcd(a_1, a_2, ..., a_n) = x $ $ 2.$ \(\sum_{i=1}^{n}a_i = y\) 题解: 可以发现,当\(y\%x!=0\)时,满足条件的序列不存在.让\(f(t)\)表示满足序列和为的 \(t…
1406A. Subset Mex https://codeforces.com/contest/1406/problem/A Example input 4 6 0 2 1 5 0 1 3 0 1 2 4 0 2 0 1 6 1 2 3 4 5 6 output 5 3 4 0 Note In the first test case,\(A=\{0,1,2\},B=\{0,1,5\}\) is a possible choice. In the second test case, \(A=\{…
题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 0 36 4 题意 给一串数,用这n个数排几种序列,使得 i=1~(n-1) 输出有几种序列满足情况 题解 附  : & -- 位运算之一,有0则0 不用怀疑,一堆数&完后,得到的数<=这堆数的任意一个数 因为每一位只要有一个数==0,这一位就=0,否则为1 记最后&完所有数的…
C. Link Cut Centroids Fishing Prince loves trees, and he especially loves trees with only one centroid. The tree is a connected graph without cycles. A vertex is a centroid of a tree only when you cut this vertex (remove it and remove all edges from…
题意:有一长度为\(n\)的序列,求其中任意五个元素乘积的最大值. 题解:先排序,然后乘积能是正数就搞正数,模拟一下就好了. 代码: int t; ll n; ll a[N]; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>t; while(t--){ cin>>n; for(int i=1;i<=n;++i){ cin>>a[i]; } sort(a+1,a+1+n);…
题意:给你一长度为\(n\)的序列,将其分为两个集合,求两个集合中未出现的最小元素的最大值, 题解:用桶存一下每个元素的个数,两次枚举\([1,100]\),找出两个最小值即可. 代码: int t; int n; int a[N]; map<int,int> mp; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>t; while(t--){ cin>>n; mp.clear(…
A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which…
题目链接 这个题取模的时候挺坑的!!! 题意:div(x , b) / mod(x , b) = k( 1 <= k <= a).求x的和 分析: 我们知道mod(x % b)的取值范围为 1  - (b-1).那么我们可以从这一点入口来进行解题.. mod (x, b) = 1 时, x  =  b + 1, 2b + 1, 3b + 1..... a * b + 1. mod (x , b) = 2 时, x =  2b + 2, 4b + 2, 6b + 2, ..... 2a * b…
https://codeforces.com/contest/1061/problem/E 题意 有n个点(<=500),标记第i个点的代价a[i],然后分别在这n个点建两棵树,对于每颗树的每个点来说,都有一个p[i],代表他的子树中被标记的点的个数需要等于p[i],请你选择需要标记的点,使得可以满足上述两棵树的要求,并且使得代价最大,输出最大的代价或者-1(不存在) 思路 这道题难在建图 首先考虑子树问题,是否选择每个节点对他的子孙节点没有影响,但是对他自身及其祖先节点有影响,注意p[i]=0…
C. Marco and GCD Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then…
题目链接:http://codeforces.com/contest/1150/problem/D 题目大意: 你有一个参考串 s 和三个装载字符串的容器 vec[0..2] ,然后还有 q 次操作,每次操作你可以选择3个容器中的任意一个容器,往这个容器的末尾添加一个字符,或者从这个容器的末尾取出一个字符. 每一次操作之后,你都需要判断:三个容器的字符串能够表示成 s 的三个不重叠的子序列. 比如,如果你的参考串 s 是: abdabc 而三个容器对应的字符串是: vec[0]:ad vec[1…
链接: https://codeforces.com/contest/1230/problem/D 题意: Marcin is a coach in his university. There are n students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other. L…
题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只有成功了才会进入下一步,失败了会从第 \(1\) 步重新开始测.请问成功的期望步数是多少? 解题思路: 设期望步数是 \(S\) ,则有公式如下: 实现代码如下: #include <bits/stdc++.h> using namespace std; typedef long long ll;…
第一次写博客 ,请多指教! 翻了翻前面的题解发现都是用树状数组来做,这里更新一个 线段树+离散化的做法: 其实这道题是没有必要用线段树的,树状数组就能够解决.但是个人感觉把线段树用熟了会比树状数组更有优势一点 不多废话  http://codeforces.com/contest/1311/problem/F 题目链接 题意是 给你一堆点的位置和他们运动的速度(可正可负),然后时间无限往后推的情况下问你他们之间所有点的最小距离之和.(不明白自行读题) n的范围是2,200000: 显然单纯的一个…
E. Two Round Dances #圆排列 题目链接 题意 \(n\)(保证偶数)个人,要表演一个节目,这个节目包含两种圆形舞蹈,而每种圆形舞蹈恰好需要\(n/2\)个人,每个人只能跳一种圆形舞. 一个节目中两支舞蹈中的人编号组成一条圆环.故两个节目,对应两个圆环排列.两个不相同的节目,等价于,两个圆排列是不同的,现要你求出他们能做出多少种不同的节目. 分析 圆排列:从\(n\)个不同元素选取\(r\)个元素,不分首尾地围成一个圆圈的排列. 其排列方案数为:\(\frac{A^r_n}{r…
题目链接:https://codeforces.com/contest/1417/problem/D 题意 给出一个大小为 $n$ 的正整数数组 $a$ ,每次操作如下: 选择 $i,j$ 和 $x$,$(1 \le i, j \le n,\ 0 \le x \le 10^9)$ 令 $a_i - x \cdot i,\ a_j + x \cdot i$ 要求过程中不能有负数产生,问能否在 $3n$ 次操作内使数组中的每个元素相等,如果可以给出操作次数和过程. 题解 把每个 $a_i$ 变为 $…
传送门 https://codeforces.com/contest/1496/problem/B 题目 Example input 5 4 1 0 1 3 4 3 1 0 1 4 3 0 0 1 4 3 2 0 1 2 3 2 1 2 3 output 4 4 3 5 3 Note In the first test case, S={0,1,3,4}S={0,1,3,4}, a=mex(S)=2a=mex⁡(S)=2, b=max(S)=4b=max(S)=4, ⌈a+b2⌉=3⌈a+b2⌉…
传送门:  https://codeforces.com/contest/1493/problem/B 题目: Example input 5 24 60 12:21 24 60 23:59 90 80 52:26 1 100 00:01 10 10 04:04 output 12:21 00:00 52:28 00:00 00:00 题意 给定一个时钟, 小时最大值与分钟最大值, 再输入一个时钟, 要求将该时钟通过镜子水平镜像后仍符合小时最大值与分钟最大值若不符合, 则时钟分钟值+1, 分钟值…
题目大意 我们说一个无向图是 p-interesting 当且仅当这个无向图满足如下条件: 1. 该图恰有 2 * n + p 条边 2. 该图没有自环和重边 3. 该图的任意一个包含 k 个节点的子图含有不超过 2 * k + p 条边 现在,请你找出一个 p-interesting 包含 n 个节点的无向图,输出他的 2 * n + p 条边 数据范围:5 ≤ n ≤ 24,0 ≤ p, 2 * n + p ≤ (n) * (n + 1) / 2 做法分析 好久没有做题了,刷刷水题练练手 第…
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed…
题目链接 题意: 1-m中,四个数凑成一组,满足任意2个数的gcd=k,求一个最小的m使得凑成n组解.并输出 分析: 直接粘一下两个很有意思的分析.. 分析1: 那我们就弄成每组数字都互质,然后全体乘以k不就行了么…… 然后看了看样例…… 这个该怎么说……我是觉得额这道题的output暴露了数据规律怎么破……我算是看出规律再证明的方式A的这道题 当时我看到22那个样例的时候……在想他干嘛要把22放这里……然后发现 2/4/6/10 14/16/18/22也是行的哇…… 化成乘以k之前的数据………
哎,今天第一次打div1 感觉头脑很不清醒... 看到第一题就蒙了,想了好久,怎么乱dp,倒过来插之类的...突然发现不就是一道sb二分吗.....sb二分看了二十分钟........ 然后第二题看了一下,感觉太码农了不可做,然后就cd逛一逛. 突然觉得c可做,就做了一下,交上去wa了,发现有情况没考虑. 这下又滚回了b,结果又没写完...... gg  2040 -83 ->1957 -----------------------------------------------我似分割线啊 A…
传送门 https://www.cnblogs.com/violet-acmer/p/10146350.html 题意: 有一块 n*m 的棋盘,初始,黑白块相间排列,且左下角为白块. 给出两个区间[ (x1,y1) , (x2,y2) ] 和 [ (x3,y3) , (x4,y4) ],第一个区间全部涂成白色,第二个区间全部涂成黑色,且颜色会覆盖. 求两块区间按照要求涂完后白块和黑快的个数? 题解: 我的想法如下: 先求出初始的黑块个数,然后,求出第一个区间减少的黑块个数,再求出第二个区间增加…
C. Three displays time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to ren…