题意:有一个非常长的板子(10000000长),在上面贴n(n<=10000)张海报。问最后从外面能看到几张不同的海报。

由于板子有10000000长,直接建树肯定会爆,所以须要离散化处理,对于每张海报,有两个端点值,最后能看到几张海报跟他们的端点值的相对大小有关,跟绝对大小无关。所以就把全部海报的端点离散化处理,总共2n个端点,排序去重,相应p(p<=2n)个点。

然后建树,由于p不超过20000,所以这样就能够接受了。区间更新时,由于我们仅仅关心最外面海报的颜色有多少种。所以向下传递节点信息的时候把上面节点的信息去掉。这样在查询的时候就能方便一些,用一个标记数组记录总共同拥有多少种颜色就能够了。

代码:

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include<climits>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,x,n) for(int i=x;i<(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define FORD(i,h,l) for(int i=(h);i>=(l);--i)
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define OI(X) printf("%d",X);
#define RS(X) scanf("%s", (X))
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define Swap(a, b) (a ^= b, b ^= a, a ^= b)
#define Dpoint strcut node{int x,y}
#define cmpd int cmp(const int &a,const int &b){return a>b;} /*#ifdef HOME
freopen("in.txt","r",stdin);
#endif*/
const int MOD = 1e9+7;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
//#define HOME int Scan()
{
int res = 0, ch, flag = 0; if((ch = getchar()) == '-') //推断正负
flag = 1; else if(ch >= '0' && ch <= '9') //得到完整的数
res = ch - '0';
while((ch = getchar()) >= '0' && ch <= '9' )
res = res * 10 + ch - '0'; return flag ? -res : res;
}
/*----------------PLEASE-----DO-----NOT-----HACK-----ME--------------------*/
int data[100000+10]; int n;
int a[20010];
int b[20010];
int u[40000]; void pushdown(int rt)
{
if(data[rt]!=-1)
{
data[rt<<1]=data[(rt<<1)+1]=data[rt];
data[rt]=-1;
}
}
void build(int l,int r,int rt)
{
if(l==r)
{
data[rt]=-1;
return;
}
int m=(l+r)>>1;
build(l,m,rt<<1);
build(m+1,r,(rt<<1)+1);
}
void update(int l,int r,int rt,int a,int b,int c)
{
if(a<=l&&r<=b)
{
data[rt]=c;
return;
}
pushdown(rt);
int m=(l+r)>>1;
if(a<=m)
update(l,m,rt<<1,a,b,c);
if(b>m)
update(m+1,r,(rt<<1)+1,a,b,c);
}
int vis[20010];
int sum;
void query(int l,int r,int rt)
{if(data[rt]!=-1)
{
if(!vis[data[rt]])
{
vis[data[rt]]=1;
sum++;
}
return;
}
int m=(l+r)>>1;
query(l,m,rt<<1);
query(m+1,r,(rt<<1)+1); } int main()
{
int c;
RI(c);
while(c--)
{RI(n);
REP(i,0,n)
{
RII(a[i],b[i]);
}
REP(i,0,n)
{
u[i]=a[i];
u[i+n]=b[i];
}
sort(u,u+2*n);
int p=unique(u,u+2*n)-u;
REP(i,0,n)
{int t=lower_bound(u,u+p,a[i])-u;
a[i]=t+1;
t=lower_bound(u,u+p,b[i])-u;
b[i]=t+1;
}
build(1,p,1);
REP(i,0,n)
{
update(1,p,1,a[i],b[i],i);
}
MS0(vis);
sum=0;
query(1,p,1);
printf("%d\n",sum);
} return 0;
}

最新文章

  1. ****Linux MySQL命令运用个人总结
  2. BizTalk Server 2016
  3. 读取bmp图片数据
  4. Servlet目录
  5. 算法实质【Matrix67】
  6. MySQL错误: could not retrieve transation read-only status server
  7. MyBatis学习系列三——结合Spring
  8. java-web查询系统
  9. fastUtils学习
  10. NHibernate之映射文件配置说明(转载1)
  11. Visual Studio Code作为Angular开发工具常用插件安装、json-server安装与使用、angular/cli安装失败问题
  12. linux下用gtk+写比赛赌博GUI小游戏
  13. Android设计模式总结
  14. Spring IoC的原理为什么是反射而不是new
  15. ELK学习笔记之F5 DNS可视化让DNS运维更安全更高效-F5 ELK可视化方案系列(3)
  16. 新版appium 支持name定位的方法(没试 记录再此)
  17. EJB到底是什么?---通俗易懂,简单明了
  18. Qt实现简单的单例模式
  19. keil的使用:新建Project
  20. Collection Types

热门文章

  1. C++中 #ifdef 和#endif的作用
  2. redis配置cluster分布式集群
  3. C#自定义Excel操作类
  4. 【01】let和const命令
  5. Appium切换webview时候报chromedriver版本问题
  6. 学习笔记3——WordPress文件目录结构详解
  7. BZOJ 3473 字符串 ——广义后缀自动机
  8. 刷题总结——瞭望塔(bzoj1038)
  9. 刷题总结——spoj1812(后缀自动机+DP)
  10. 2013年EI收录的中国期刊