题解-CF1389F Bicolored Segments】的更多相关文章

题面 CF1389F Bicolored Segments 给 \(n\) 条线段 \([l_i,r_i]\),每条有个颜色 \(t_i\in\{0,1\}\),求最多选出多少条线段,使没有不同颜色的线段相交. 数据范围:\(1\le n\le 2\cdot 10^5\),\(1\le l_i\le r_i\le 10^9\). 蒟蒻语 昨天蒟蒻打 CF,发挥得不错,迷惑回橙.但是蒟蒻没做出这题,赛后想了好久感觉这题很奇妙,于是蒻蒻地来写篇题解. 蒟蒻解一 线段树维护 dp. 先将每条线段 \(…
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20min 我说这句话,肯定是有原因的,我们看到 \(\operatorname{lcm}\) 会想到之前一些题:题目,我的题解 自然就往 \(a\times b=\operatorname{gcd}(a,b)\times \operatorname{lcm}(a,b)\) 的方向思考,但是,这太麻烦了,…
题意:之前愣是没看懂题意...就是给你n个点的坐标xi,然后还规定了Li,Ri,要求给每个点染色,每一组L,R内的点红色和黑色的个数不能相差大于1个,问你能不能染成功,不能输出-1,能就按照输入的顺序输出颜色 思路:我会说我根本没想到怎么做吗?显然只要交替染色相差就不会大于1 代码: #include<set> #include<map> #include<stack> #include<cmath> #include<queue> #inclu…
1.题目描述 2.题目分析 找到字符串中的空格即可 3.代码 int countSegments(string s) { ){ ; } vector<string> v; ; i < s.size(); i++){ if( isspace(s[i]) ){ continue; } ; while( !isspace(s[j]) ){ if( j < s.size() ) j++; else break; } string sb = s.substr(i,j-i); v.push_b…
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h> using namespace std; /* 对于第i个数字(i=0~n-1),它每组出现的次数为n-i,出现在前i+1个组中 */ +; double num[maxn]; int main() { int n; scanf("%d",&n); double sum=0.…
http://poj.org/problem?id=3304 题目大意:给n条线段,求是否存在一条直线,将所有线段投影到上面,使得所有投影至少交于一点. ———————————————————————————— 首先考虑当情况可能时,过相交点做垂线,则垂线一定与所有线相交. 所以就变成了求是否存在一条直线,使得直线和所有直线都相交的问题了. 显然如果存在这样的线,那么至少有一种情况,这样的线的两个端点是其中两条直线的任意两个端点. 那么枚举两个端点判断即可. https://www.cnblog…
模拟两个颜色的扩号层数,贪心,如果是左括号,哪边的层数浅就放那边:如果是右括号,哪边的层数深就放那边. 至于层数的维护,两个int就做掉了 放个代码: #include <cstdio> #include <iostream> #include <string> using namespace std; inline int read(){ int x = 0; int zf = 1; char ch = ' '; while (ch != '-' &&…
我们暴力枚举一下\(delim_{1}\) 然后对于每个\(delim_{1}\),O(n)扫一遍+前缀和求出最大\(delim_{0}\)和\(delim_{2}\),然后记录一下它们的位置就行啦 放个代码 #include <cstdio> #define ll long long inline ll read(){ ll x = 0; int zf = 1; char ch = ' '; while (ch != '-' && (ch < '0' || ch >…
题目戳我 \(\text{Solution:}\) 若\([l,r]\)子段和是\(0,\)则\(sum[r]=sum[l-1].\) 于是我们可以考虑维护当前哪一个前缀和出现过.对于区间\([l,r]\)若其子段和为\(0\)则在\(r-1\)的地方插入一个\(+\infty\)即可. 初始化要把\(0\)赋值为出现过. #include<bits/stdc++.h> using namespace std; int n,a[500010]; map<long long,bool>…
D. Vika and Segments     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 horizontal and vertical segments parallel to the coordinate axes.…