题意:给你若干个区间,询问每个区间包含几个其它区间 分析:区间范围比较大,然后离散化,按右端点排序,每次更新树状数组中的区间左端点,查询区间和 注:(都是套路) #include<cstdio> #include<cstring> #include<queue> #include<cstdlib> #include<algorithm> #include<vector> #include<cmath> using name…
题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点值离散化,按照左端点从大到小排序,顺着这个顺序处理所有线段,那么满足在它内部的线段一定是之前已经扫到过的.用树状数组判断有多少是在右端点范围内. #include <iostream> #include <vector> #include <algorithm> #incl…
花了近5个小时,改的乱七八糟,终于A了. 一个无限数列,1,2,3,4,...,n....,给n个数对<i,j>把数列的i,j两个元素做交换.求交换后数列的逆序对数. 很容易想到离散化+树状数组,但是发现那些没有交换的数也会产生逆序对数,但我没有算. 经明神提示, 把没有用到的数字段化成点.然后用树状数组算一下就好了. 然后我用一个数组记录每个点的长度.比如 <1,2><5,6>,1,2,3,4,5,6只有1,2,5,6用到了,那么离散化为1,2,3,4,5,f[1]=…
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…
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…
题目链接 参考博客 题意: 给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…
题目链接 我们将线段按照右端点从小到大排序, 如果相同, 那么按照左端点从大到小排序. 然后对每一个l, 查询之前有多少个l比他大, 答案就是多少.因为之前的r都是比自己的r小的, 如果l还比自己大的话, 那么自己就可以包含它. 记得离散化. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #includ…
 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…
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection. The input data guarant…