离散化  去掉重复点 排序  二分查找

#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 40005 using namespace std; int pp[maxn][2];
int x[2*maxn],f[2*maxn];
int d[2*maxn]; int main()
{
int t;
scanf("%d",&t);
while (t--)
{
memset(f, 0 ,sizeof(0));
int n;
scanf("%d",&n);
for(int i= 0; i < n; i++)
{
scanf("%d%d",&pp[i][0],&pp[i][1]);
x[i] = pp[i][0];
x[2*i+1] = pp[i][1];
}
sort(x, x+2*n);
d[0] = x[0];
int cc = 1;
for(int i = 1; i < 2*n; i++)
{
if(x[i] != d[cc-1])
{
d[cc++] = x[i];
}
}
for(int i = 0; i < n; i++)
{
int ri = lower_bound(d, d+cc, pp[i][0])-d;
int le = lower_bound(d, d+cc, pp[i][1])-d;
for(int j = ri; j <= le; j++)
f[j] = i;
}
sort(f, f+cc);
int ans = 1;
for(int i = 1; i < cc; i++)
{
if(f[i] != f[i-1])
ans++;
}
printf("%d\n",ans);
}
return 0;
}

spoj 138的更多相关文章

  1. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  2. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  3. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  4. CF#138 div 1 A. Bracket Sequence

    [#138 div 1 A. Bracket Sequence] [原题] A. Bracket Sequence time limit per test 2 seconds memory limit ...

  5. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

  6. SPOJ bsubstr

    题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...

  7. 【SPOJ 7258】Lexicographical Substring Search

    http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...

  8. 【SPOJ 1812】Longest Common Substring II

    http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...

  9. 【SPOJ 8222】Substrings

    http://www.spoj.com/problems/NSUBSTR/ clj课件里的例题 用结构体+指针写完模板后发现要访问所有的节点,改成数组会更方便些..于是改成了数组... 这道题重点是求 ...

随机推荐

  1. ARM你必须知道的事儿——为啥“PC = PC + 8”?

    为啥是“PC = PC + 8”: “PC = PC + 8”其实这样写容易让人蒙了.“PC = PC + 8”真正含义应该是: 执行处代码地址 = PC - 8: 也就是说,”PC指向的地址“领先“ ...

  2. 【leetcode】15. 3Sum

    题目描述: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find ...

  3. c语言 char*类型作为中间变量将许多字符串保存到一个数组的问题

    char*是一个字符串指针,如下面的程序value_作为一个中间变量用来在for循环中scanf输入的值的接收者,然后将value_保存到array中,但是一下程序会出现一个问题就是当你跳出这个函数时 ...

  4. Linux美化——终端提示符

    1. PS1变量简介[1] PS1是Linux终端用户的一个环境变量,用来说明命令行提示符的设置. 可以使用 man bash命令查看bash手册,找到该变量支持的特殊字符,以及这些特殊字符的意义: ...

  5. linux中nodejs后台运行工具forever

    forever让nodejs应用后台执行 命令如下: forever start './bin/www' nodejs一般是当成一条用户命令执行的,当用户断开客户连接,运用也就停了,很烦人.如何让no ...

  6. 免费GIT托管

    http://www.gitcentral.com http://www.projectlocker.com http://gitfarm.appspot.com http://code.google ...

  7. C# 查处出现次数最多的元素

    LINQ var str= str.ToCharArray() .GroupBy(x => x) .OrderByDescending(x => x.Count()) .First() . ...

  8. 转发 python中file和open有什么区别

    python中file和open有什么区别?2008-04-15 11:30地痞小流氓 | 分类:python | 浏览3426次python中file和open有什么区别?都是打开文件,说的越详细越 ...

  9. 【转】Eazfuscator.NET 3.3中混淆化需要注意的一些问题

    对于DLL,Eazfuscator.NET默认不会混淆化任何公共成员,因为类库的公共成员很有可能被外界调用,而对于EXE的程序集,所有类型都可能被混淆化.注意上面这句话有一个“可能”,因为Eazfus ...

  10. linux c 分解质因数

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> ...