题意:有一个长度为\(n\)元素均为\(0\)的序列,进行\(n\)次操作构造出一个新序列\(a\):每次选择最长的连续为\(0\)的区间\([l,r]\),使得第\(i\)次操作时,\(a[\frac{l+r}{2}]=i\)(下取整),求\(a\). 题解:刚开始我打算用归并分治的思想来写,但是发现左区间递归不到,然后就gg了. ​ 之后才发现这题用_优先队列_直接模拟就过了,题目就不说了,这儿讲一下优先队列. 优先队列与队列的区别在于,优先队列是按照某种优先级来决定谁在队头,C++默认它是…
比赛链接:https://codeforces.com/contest/1353 A - Most Unstable Array 题意 构造大小为 $n$,和为 $m$ 的非负数组 $a$,使得相邻元素之差的绝对值之和最大. 题解 稍加推导发现:将 $m$ 拆分和单独用 $m$ 结果是一样的,所以可以直接用 $0$ 和 $m$ 构造. 代码 #include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin &g…
A. Greg and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/295/problem/A Description Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ri ≤ n). To apply operation …
B. Wilbur and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/problem/B Description Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he…
题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把下降段的起始位置和结束位置记录下来然后进行推断,在进行推断时,有几种特殊情况:(s表示起始位置,e表示结束位置) 1.当e==n&&s!=1时,满足a[n]>a[s-1]输出yes: 2当s==1&&==n时,满足a[1]<a[e+1] 输出yes: 3当s==1&…
http://codeforces.com/contest/1042/problem/D 题意 给一个数组n个元素,求有多少个连续的子序列的和<t (1<=n<=200000,abs(a[i])<=1e9) 思路 将公式转化以下,sum[r]-sum[l-1]<t 变成 sum[r]<sum[l-1]+t 可以考虑遍历每个r,先更新sum[r-1]+t,统计有多少满足条件的sum[l-1],反向树状数组维护即可 实现细节 对于每个r是更新他的sum[r-1] 因为要统计…
D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer x and decided to add or…
E. Sasha and Array 题目连接: http://codeforces.com/contest/719/problem/E Description Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types: 1 l r x - increase all integers on the segment from l…
B. DZY Loves Modification 题目连接: http://www.codeforces.com/contest/446/problem/B Description As we know, DZY loves playing games. One day DZY decided to play with a n × m matrix. To be more precise, he decided to modify the matrix with exactly k opera…
http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的数,只要有一个不为0的数,那么就能分割. 如果一个数不为0,则让它单独成为一组,如果它后面有0,则把它后面的连续的0也归到这一组中. 特别要注意一下的是,序列一开始就是0的情况. #include<iostream> #include<algorithm> #include<cs…