CF - 652 D Nested Segments】的更多相关文章

题目传送门 题解: 可以将所有线段按照左端点优先小,其次右端点优先大进行排序. 然后对于第 i 条线段来说, 那么第 i+1 ---- n 的线段左端点都一定在第i条线段的右边, 接下来就需要知道 i+1 ---- n 中的这些线段有多少条的右端点是在第 i 条线段的右端点的左边. 可以通过一个树状数组来维护一个右端点的前缀合. 当我门处理第i条线段的时候, 先将第i条线段的右端点从树状数组里面删除,然后在询问在 r 之前有多少个右端点就是相应的答案了. 代码: /* code by: zstu…
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…
任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given n segments on a line. There are no ends of some segments th…
Nested Segments Time limit: 1.0 secondMemory limit: 64 MB You are given n segments on a straight line. For each pair of segments it is known that they either have no common points or all points of one segment belong to the second segment. Then m quer…
 Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of s…
题目链接: D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the num…
D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of…
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…
Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of se…
题面: 传送门 C. Nested Segments Input file: standard input Output file: standard output Time limit: 2 second Memory limit: 256 megabytes   You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two di…
题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点值离散化,按照左端点从大到小排序,顺着这个顺序处理所有线段,那么满足在它内部的线段一定是之前已经扫到过的.用树状数组判断有多少是在右端点范围内. #include <iostream> #include <vector> #include <algorithm> #incl…
题目链接:http://codeforces.com/problemset/problem/652/D 给你n个不同的区间,L或者R不会出现相同的数字,问你每一个区间包含多少个区间. 我是先把每个区间看作整体,按照R从小到大排序.然后从最小的R开始枚举每个区间,要是枚举到这个区间L的时候,计算之前枚举的区间有多少个Li在L之后,那么这些Li大于L的区间的数量就是答案.那我每次枚举的时候用树状数组add(L , 1) 说明在L这个位置上出现了区间,之后枚举的时候计算L之前的和,然后i - 1 -…
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) — the number of segments on a line. Each…
You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1…
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1987 题意:给定n条线段,每两条线段要么满足没有公共部分,要么包含.给出m个询问,求当前点被覆盖的最小长度的线段编号. 由于线段不存在部分相交的情况,因此,直接按照输入顺序覆盖区间就可以了,因为后覆盖的线段更短. //STATUS:C++_AC_187MS_6805KB #include <functional> #include <algorithm> #include…
题意:给你若干个区间,询问每个区间包含几个其它区间 分析:区间范围比较大,然后离散化,按右端点排序,每次更新树状数组中的区间左端点,查询区间和 注:(都是套路) #include<cstdio> #include<cstring> #include<queue> #include<cstdlib> #include<algorithm> #include<vector> #include<cmath> using name…
题目链接 我们将线段按照右端点从小到大排序, 如果相同, 那么按照左端点从大到小排序. 然后对每一个l, 查询之前有多少个l比他大, 答案就是多少.因为之前的r都是比自己的r小的, 如果l还比自己大的话, 那么自己就可以包含它. 记得离散化. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #includ…
离散化+树状数组 先对坐标离散化,把每条线段结尾所在点标1, 询问某条线段内有几条线段的时候,只需询问这段区间的和是多少,询问结束之后再把这条线段尾部所在点标为0 #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<algorithm> using namespace std; *1e5+; struct X { int x,y,ans,id; }…
题意给定一个长度为n的序列,和m个区间.对一个区间的操作是:对整个区间的数-1可以选择任意个区间(可以为0个.每个区间最多被选择一次)进行操作后,要求最大化的序列极差(极差即最大值 - 最小值).easy version的范围是(1≤n≤300,0≤m≤300)hard version的范围是(1≤n≤1e5,0≤m≤300) 分析: 我们可以通过枚举最大或者最小值出现的位置 , 然后把不包括最大值位置或者包括最小值位置的区间选取 , 如果数据小我们是可以通过暴力的 , 但是这里的n有1e5 ,…
题目传送门 题解总结起来其实很简单. 把所有的边双联通分量缩成一个点,然后建立好新边, 然后再从起点搜到终点就好了. 代码: /* code by: zstu wxk time: 2019/02/23 */ #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w…
题目链接 参考博客 题意: 给n个线段,对于每个线段问它覆盖了多少个线段. 思路: 由于线段端点是在2e9范围内,所以要先离散化到2e5内(左右端点都离散化了,而且实际上离散化的范围是4e5),然后对右端点升序排序: 例如 2 3  5 6  4 7  1 8 这样的话,如果对i<j,a[ i ].l >= a[ j ].l ,那么第 j 组一定包含了第 i 组,算完第一组sum(3)-sum(2-1),把a[1].l加入到树状数组中,再算第二组,以此类推算到第三组时,sum(7)=2(1~7…
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取模. 因为取模后至少减半, 复杂度$O(nlognlogC)$ 2. CF 431E Chemistry Experiment 大意: n个试管, 第$i$个试管有$a_i$单位水银, m个操作: 1, 修改$a_x$改为$v$. 2, 将$v$单位水倒入试管, 求一种方案使得有水的试管水银与水总量的最大…
A:Gabriel and Caterpillar 题意:蜗牛爬树问题:值得一提的是在第n天如果恰好在天黑时爬到END,则恰好整除,不用再+1: day = (End - Begin - day0)/(12*(up-down))+1; #include <iostream> #include <algorithm> #include <stdlib.h> #include <time.h> #include <cmath> #include &l…
From:http://secureallthethings.blogspot.jp/2014/08/patching-mach-o-format-simple-and-easy.html I'm relatively new to mac research.  So when I find something new, that seems cutting edge, but relatively simple I question it. Has anyone else done this…
A. Minimum Binary Number time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output String can be called correct if it consists of characters "0" and "1" and there are no redundant lead…
Educational Codeforces Round 43  A. Minimum Binary Number 显然可以把所有\(1\)合并成一个 注意没有\(1\)的情况 view code //#pragma GCC optimize("O3") //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<bits/stdc++.h> using namespace std…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array of n integer numbers. Let sum(l, r) be the sum of all numbers on positions from l to r non-inclusive (l-th element is…
题目地址 http://codeforces.com/contest/1196/problem/B B. Odd Sum Segments time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array aa consisting of nn integers a1,a2,…,ana1,a2,…,…
没什么好说的 #include<iostream> using namespace std; ], x, y,n, m, ans; int main(){ cin>>n>>m; ;i<=n;++i){ cin>>x>>y; a[x]++; --a[y+]; } ;i<=;++i) a[i]+=a[i-]; ;i<=m;++i) )ans++; cout<<ans<<endl; ;i<=m;++i)…
传送门 题意:    有m个区间,n个a[ i ] , 选择若干个区间,使得整个数组中的最大值和最小值的差值最小.n<=1e5,m<=300; 思路: 可以知道每个i,如果一个区间包含这个点,就让这个区间发挥作用.枚举每个i,找到最大值即可. 当然这个复杂度不对,我们可以通过线段树保存数组的最大值和最小值,每次区间在左端点发挥作用,在右端点去掉作用. #include <algorithm> #include <iterator> #include <iostre…