【CodeForces 624D/623B】Array GCD】的更多相关文章

题 You are given array ai of length n. You may consecutively apply two operations to this array: remove some subsegment (continuous subsequence) of length m < n and pay for it m·a coins; change some elements of the array by at most 1, and pay b coins…
You are given positive integer number n. You should create such strictly increasingsequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of…
转载请注明出处:http://www.cnblogs.com/Delostik/p/3553114.html 目前已有[A B C D E] 例行吐槽:趴桌子上睡着了 [A. Genetic Engineering] http://codeforces.com/contest/391/problem/A 问最少插入几个字符,使得字符串不存在连续偶数个相同字母.不说什么 #include <iostream> #include <string> using namespace std…
题 You are given array ai of length n. You may consecutively apply two operations to this array: remove some subsegment (continuous subsequence) of length m < n and pay for it m·a coins; change some elements of the array by at most 1, and pay b coins…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecu…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a str…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participat…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and th…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization…
[链接] 我是链接,点我呀:) [题意] [题解] 分类讨论一波 设第一个数组的奇数个数为cnt1 第二个数组的奇数个数为cnt2 显然只有在(cnt1+cnt2)%2==0的情况下. 才可能第一个数组的和为偶数,第二个数组的和也为偶数 (因为奇数都要出现偶数次才可以. 所以只可能cnt1和cnt2都是偶数,那么输出0 否则,cnt1和cnt2都是奇数,看看有没有一个位置i只有a[i]或只有b[i]是奇数.有的话输出1. 其他情况都非法. [代码] #include <bits/stdc++.h…
模拟CF650,ABC三题,RK90 Codeforces 650 A 思路:首先看式子 \(\sqrt{(x_i-x_j)^2+(y_i-y_j)^2}=|x_i-x_j|+|y_i-y_j|\) 的唯一可行的情况是\(x_i=x_j\)或\(y_i=y_j\).(因为两边之和大于第三边 所以就知道怎么做了. 第一种方法:我们维护三个\(map\),分别存行.列.坐标是\(\dots\)的时候已经有多少个节点. 然后就可以边读边算,读到\((x,y)\)这个坐标的时候把\(ans\)变成 \(…
模拟Canada Cup 2016,ABC三题,Rank1376 第三题卡住了 Codeforces 725 C 求出两个相同字符的位置,记为x和y. 然后考虑把相同的那个字符放在第一行的什么地方, 然后把x+1..y-1的部分一折两半,放在第一行的末尾再折回第二行. 再把1..x-1和y+1..n放下来就可以了. Codeforces 725 D 题意:有n个队伍,你是第一个队伍的一员,然后你可以把你们队伍拿到的一些气球给其他的队伍,如果一个队伍的气球数量大于他们的质量,那么他们就会被删除.…
模拟RD265 ABC三题,Rank58 Codeforces 464 A 题意:给定一个字符串,求比这个字符串字典序大并且和它长度相等的第一个不含有长度大于等于2的回文串的字符串. 思路:首先我们枚举最后一个与原串相等的位置,从后往前枚举,因为我们需要的是第一个字典序大于给定串的. 然后就枚举我们将下一个字符改变成了什么,再按照这种方法继续填充完整答案串即可. Codeforces 464 B 题意:给8个\((x,y,z)\)三元组,但是每个三元组的内部顺序可能是错乱的,问是否有可能把这些三…
Codeforces Round 1137 这场比赛做了\(A\).\(B\),排名\(376\). 主要是\(A\)题做的时间又长又交了两次\(wa4\)的. 这两次错误的提交是因为我第一开始想的求最大值很不对,竟然还有\(min\)在里面... Codeforces 1137 A 题意:给一个矩阵,问对于每一个格子\((x,y)\),把第\(x\)行和第\(y\)列的值取出,要求将它们每一个赋上一个正整数,要求同一行.列中大小关系依然相同,问最大的数. 思路:我们先考虑每一行(列)的数们把它…
Codeforces Round 1132 这场比赛做了\(A\).\(B\).\(C\).\(F\)四题,排名\(89\). \(A\)题\(wa\)了一次,少考虑了一种情况 \(D\)题最后做出来,但被\(hack\)了...被\(hack\)的原因是没有想到答案会超过\(10^{12}\)(毕竟这个时间上的优化也是在最后迫不得已的情况下加的,就没有考虑正确性... Codeforces 1132 C 题意:给一些区间\([l_i,r_i]\),从中删掉两个,求剩下的区间最多能够覆盖的格子数…
Codeforces Round 1120 这场比赛做了\(A\).\(C\)两题,排名\(73\). \(A\)题其实过的有点莫名其妙...就是我感觉好像能找到一个反例(现在发现我的算法是对的... \(C\)题的心路历程: 第一眼:这不后缀自动机吗??? 算了滚去写哈希表乱搞吧... 嗯怎么\(mle\)了???算了把数组改成\(vector\)吧... 嗯怎么又\(wa\)了???算了我还是老老实实去敲SAM吧... 嗯???\(pretest\ passed\)??!! 所以就交了\(3…
Codeforces Round 1129 这场模拟比赛做了\(A1\).\(A2\).\(B\).\(C\),\(Div.1\)排名40. \(A\)题是道贪心,可以考虑每一个站点是分开来的,把目的地最小编号的留到最后,所以答案稍微算一下就行了. \(B\)题是道找规律,首先可以很容易地发现只要前面弄个负数的开头,错误算法就会忽略掉这一个值,所以利用这个来构造答案.(最讨厌构造题了)然后推导一番式子就会发现如果我们将第一个值放-1,则 \(\sum_{i=2}^na_i=k+n\), 再更改一…
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K,如果第L位已经有值了就会先调用\(Insert(L+1,A_L)\)(其中\(A_L\)表示第L位上的值),再将\(A_L\)赋为K.问经过查询后序列的模样. 思路:首先将题意抽象成每次找到从第L位开始第一个0,并将其"拖"回第L位,然后将其更改为K.这个操作很明显可以用FHQ Treap…
Codeforces Round 1117 这场比赛做了\(A\).\(B\).\(C\).\(D\).\(E\),\(div.2\)排名\(31\),加上\(div.1\)排名\(64\). 主要是\(A\)题卡了很久,直到第\(52\)分钟才做出来,思路固化了,一直没想到最大平均值的区间就是只含有最大值的区间.幸好节奏没有受到太大影响. 最后去肝\(G\),最后一分钟一把过了样例,就赶紧交,结果\(ce\)了...实在是...是因为我定义重数组,而条件编译使我看不出有问题(这段快读的代码本机…
Codeforces Round 1114 这场比赛做了\(A\).\(C\).\(D\).\(E\),排名\(134\). \(B\)题做了很长时间,好不容易最后一分钟\(Pretest\ Passed\)了,但是又\(FST\)了... \(C\)题\(wa7\)了一次,因为爆\(long\ long\)了 \(E\)题\(wa1\)了一次,因为最后的输出格式错了…
Codeforces Round 1110 这场比赛只做了\(A\).\(B\).\(C\),排名\(905\),不好. 主要的问题在\(D\)题上,有\(505\)人做出,但我没做出来. 考虑的时候方向不对,一直抠一个思路不放,然后就一直做不出来. 虽然我中间也考虑过其他的思路,但是都没有思考完善,于是就一直在给我原来的方法加补丁. Codeforces 1110 D 题意:给定一个序列,问最多可以把该序列分成几个满足下列两个条件之一的三元组: 这三个数字相同 这三个数字为连续的三个数 思路:…
gcd(x,y)(1<=x,y<=n)为素数(暂且把(x,y)和(y,x)算一种) 的个数 <=> gcd(x/k,y/k)=1,k是x的质因数 的个数 <=> Σφ(x/k) (1<=x<=n,k是x的质因子) 这样的复杂度无法接受, ∴我们可以考虑枚举k,计算Σφ(q/k) (k是n以内的质数,q是n以内k的倍数),即Σ[φ(1)+φ(2)+φ(3)+...+φ(p)] (p=n/k) 介个phi的前缀和可以预处理粗来. 但是(x,y)和(y,x)并不同…
题目:http://codeforces.com/problemset/problem/391/E2    题意:有三棵树.每棵树有ni个结点,加入两条边把这三棵树连接起来,合并成一棵树.使得合并的树中随意两点之间的最短路径    的和最大. 分析:    三棵树要合并成一棵树,则第一棵树必须选择一个点,如果为X.第二棵树必须选择两个点,如果为Y1, Y2,第三棵树必须选择一个点,如果为Z    记第一棵树中全部结点到X的路径总和为:tot1    第二棵树中全部结点到Y1,Y2的路径总和分别为…
                                                        C. An impassioned circulation of affection                                                                time limit per test  2 seconds                                                          …
题意:给一个序列以及\(n\)个查询,每一个查询是问(假装)把第\(a_i\)个数改为\(b_i\)之后原序列的最长上升子序列的长度. 思路:线段树优化\(dp\). 肯定离线做啊. 首先我们考虑\(dp\)的状态是\(dp_L(i)\)表示以第\(i\)位为结束的最长上升子序列的长度和方案数\(mod\ 998244353\). 之所以方案数要模某个数是因为这个方案数太大太大了,肯定爆\(long\ long\). 就因为这个我\(wa\)了一次\(test\ case\ 13\). 开心的不…
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two stu…
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. Input The first…
题意 给定$n$个数,将其划分成若干个连续的子序列,求最小价值,数组价值定义为,数组和减去$\lfloor \frac{k}{c} \rfloor$,$k$为数组长度,$c$为给定数 可以列得朴素方程$f_i=\min_{j \le i} {f_j+w(j+1,i)}$,复杂度$O(n^2)$ 考虑划分的区间长度$k$,若$k=c$,那么只需要去掉区间的最小值,若$k$是$c$的整数倍,那么需要去掉$k/c$个最小值,那么把$k$分成$k/c$个长度为$c$的段,删除的最小值为每个段的最小值之和…
A:https://www.cnblogs.com/myx12345/p/9872082.html B:https://www.cnblogs.com/myx12345/p/9872124.html C:https://www.cnblogs.com/myx12345/p/9872262.html D:https://www.cnblogs.com/myx12345/p/9872409.html E: F: G:…