Four Segments CodeForces - 846C】的更多相关文章

题目 题意:sum(l,r)表示数列a中索引为l到r-1(都包含)的数之和(如果l==r则为0).给出数列a,求合适的delim0, delim1, delim2,使res = sum(0, delim0) - sum(delim0, delim1) + sum(delim1, delim2) - sum(delim2, n)最大. 方法:枚举delim1,扫一遍就可以求出此时能使res最大的delim0和delim2.记录res最大值.实现有一些细节,比如可以将res的计算公式化为前缀和的公式…
D - Nested Segments CodeForces - 652D You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input The first line contains a single integer n (1 ≤ n ≤ 2·105) - t…
Description You are given an integer N. Consider all possible segments (线段,划分)on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be  of them. You want to draw these segments in several laye…
http://codeforces.com/problemset/problem/620/F 此题是莫队,但是不能用一般的莫队做,因为是最优化问题,没有办法在删除元素的时候维护答案. 这题的方法(好像还有个名字叫"回滚莫队“,说明:https://blog.csdn.net/maverickfw/article/details/72988286): 官方题解:http://codeforces.com/blog/entry/22936 设完成一次"加入贡献"的操作的复杂度是O…
题解: 方法非常巧妙的一道题 首先考虑要求全部为0怎么做 发现是个欧拉回路的问题(很巧妙) 直接dfs一遍就可以了 而这道题 要求是-1,1,0 我们可以先离散化 完了之后判断每个点被奇数还是偶数条边覆盖 如果是奇数,那么就多连一条边 另外有个细节是为了要用欧拉回路区间左开右闭 代码: #include <bits/stdc++.h> using namespace std; const int N=4e5; ; int n,cnt[N],rd[N],b[N],head[N],l1; stru…
大意: 给定无向图, 无偶环, 每次询问求[l,r]区间内, 有多少子区间是二分图. 无偶环等价于奇环仙人掌森林, 可以直接tarjan求出所有环, 然后就可以预处理出每个点为右端点时的答案. 这样的话区间询问等价于区间求和, 特殊处理一下左右边界的环即可. 要注意同一个点可能属于多个环!! #include <iostream> #include <iostream> #include <algorithm> #include <cstdio> #incl…
D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black hor…
codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\(k\)满足:\[a_i \le k \le a_j\] 思路: 整体数组排序,对于当前\(a_i\)寻找符合条件的\(a_j\)的最大值和最小值 有:\[(a_i-1)/x+k=a_j/x\] 所以可以通过二分查找获得,这里我寻找\(((a_i-1)/x+k)*x\)为下界,\(((a_i-1)/x…
C. Four Segments 题目连接: http://codeforces.com/contest/14/problem/C Description Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while,…
D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input The first line…