线段树,排序。

按照$R$从小到大排序之后逐个检查,如果$L$,$R$最大值不超过$2$,那么就把这个区间放进去,区间$+1$,否则不能放进去。

#include<bits/stdc++.h>
using namespace std; int T,n,sz;
int a[];
struct X { int L,R,id; }s[];
int f[],m[];
int P; bool cmp(X a,X b)
{
return a.R<b.R;
} int get(int x)
{
int ll=,rr=sz,res;
while(ll<=rr)
{
int mid = (ll+rr)/;
if(a[mid]>x) rr=mid-;
else if(a[mid]==x) return mid;
else ll=mid+;
}
} void pushDown(int rt)
{
if(f[rt]==) return ;
f[*rt]+=f[rt];
f[*rt+]+=f[rt];
m[*rt]+=f[rt];
m[*rt+]+=f[rt];
f[rt]=;
} void update(int L,int R,int val,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
f[rt]+=val;
m[rt]+=val;
return ;
} pushDown(rt);
int mid = (l+r)/;
if(L<=mid) update(L,R,val,l,mid,*rt);
if(R>mid) update(L,R,val,mid+,r,*rt+);
m[rt] = max(m[*rt],m[*rt+]);
} void query(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
P=max(P,m[rt]);
return ;
} pushDown(rt);
int mid = (l+r)/;
if(L<=mid) query(L,R,l,mid,*rt);
if(R>mid) query(L,R,mid+,r,*rt+);
m[rt] = max(m[*rt],m[*rt+]);
} void build(int l,int r,int rt)
{
m[rt] = ;
f[rt] = ;
if(l==r) return ; int mid = (l+r)/;
build(l,mid,*rt);
build(mid+,r,*rt+);
} int ans[],q; int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
sz=;
for(int i=;i<=n;i++)
{
scanf("%d%d",&s[i].L,&s[i].R);
sz++; a[sz]=s[i].L;
sz++; a[sz]=s[i].R;
} sort(a+,a++sz); for(int i=;i<=n;i++)
{
s[i].L=get(s[i].L);
s[i].R=get(s[i].R);
s[i].id=i;
} sort(s+,s++n,cmp); q=; build(,sz,); for(int i=;i<=n;i++)
{
P=;
query(s[i].L,s[i].R,,sz,);
if(P==)
{
ans[q++]=s[i].id;
continue;
}
else update(s[i].L,s[i].R,,,sz,);
} sort(ans,ans+q);
printf("%d\n",q);
for(int i=;i<q;i++)
{
printf("%d",ans[i]);
if(i<q-) printf(" ");
}
printf("\n"); }
return ;
}

ZOJ 3953 Intervals的更多相关文章

  1. ZOJ - 3953 Intervals 【贪心】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3953 题意 给出N个区间,求去掉某些区间,使得剩下的区间中,任何 ...

  2. Intervals ZOJ - 3953 (区间贪心)

    Chiaki has n intervals and the i-th of them is [li, ri]. She wants to delete some intervals so that ...

  3. ZOJ 3953:Intervals(优先队列+思维)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5572 题意:给出n个线段,问最少删除几个线段可以使得任意一个点不会被三个以上的 ...

  4. POJ 1201 &amp; HDU1384 &amp; ZOJ 1508 Intervals(差分约束+spfa 求最长路径)

    题目链接: POJ:http://poj.org/problem?id=1201 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1384 ZOJ:htt ...

  5. 扫描线(线段树)+贪心 ZOJ 3953

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5572 Intervals Time Limit: 1 Second       ...

  6. zoj 1508 Intervals (差分约束)

    Intervals Time Limit: 10 Seconds      Memory Limit: 32768 KB You are given n closed, integer interva ...

  7. poj 1201/zoj 1508 intervals 差分约束系统

      // 思路 : // 图建好后 剩下的就和上一篇的 火烧连营那题一样了 求得解都是一样的 // 所以稍微改了就过了 // 最下面还有更快的算法 速度是这个算法的2倍#include <ios ...

  8. zoj3953 Intervals 最大不重叠区间加强版 zoj排名第一~

    Intervals Time Limit: 1 Second      Memory Limit:65536 KB      Special Judge Chiaki has n intervals ...

  9. zoj 1508 poj 1201 Intervals

    差分约束系统. #include<cstdio> #include<cstring> #include<cmath> #include<vector> ...

随机推荐

  1. linux shell学习五

    参考:https://www.linuxdaxue.com/ Shell函数 因为函数是脚本类语言,在执行时是逐行执行的,因此,Shell 函数必须先定义后使用. Shell 函数的定义格式如下: [ ...

  2. vue-router的link样式设置问题

    发现router-link添加上去后文字上会出现下划线,打开调试工具发现router-link其实是由a来实现的,在reset的时候 a { text-decoraction: none; } 至于点 ...

  3. KMP next表模板

    void makeNext(const char P[],int next[]) { int q,k;//q:模版字符串下标:k:最大前后缀长度 int m = strlen(P);//模版字符串长度 ...

  4. matlab的rem()和mod()函数

    matlab的rem()和mod()函数 rem(x,y):求整除x/y的余数 mod(x,y):求模 rem(x,y)=x-y.*fix(x./y);  (fix()向0取整) mod(x,y)=x ...

  5. C++ 的getline问题

    在用c++的getline函数的时候碰到两个问题,总结如下: 1.有时候写程序的时候我们会发现getline(cin,str);这样的语句是不会执行,而是直接跳过的, 一般的解决方法是getline一 ...

  6. 【BZOJ】2466: [中山市选2009]树 高斯消元解异或方程组

    [题意]给定一棵树的灯,按一次x改变与x距离<=1的点的状态,求全0到全1的最少次数.n<=100. [算法]高斯消元解异或方程组 [题解]设f[i]=0/1表示是否按第i个点的按钮,根据 ...

  7. iOS7下滑动返回与ScrollView共存二三事

    [转载请注明出处] = =不是整篇复制就算注明出处了亲... iOS7下滑动返回与ScrollView共存二三事 [前情回顾] 去年的时候,写了这篇帖子iOS7滑动返回.文中提到,对于多页面结构的应用 ...

  8. CodeForces - 1015D

    There are nn houses in a row. They are numbered from 11 to nn in order from left to right. Initially ...

  9. Go语言 7 并发编程

    文章由作者马志国在博客园的原创,若转载请于明显处标记出处:http://www.cnblogs.com/mazg/ Go学习群:415660935 今天我们学习Go语言编程的第七章,并发编程.语言级别 ...

  10. Go语言 5 函数

    文章由作者马志国在博客园的原创,若转载请于明显处标记出处:http://www.cnblogs.com/mazg/ 今天,我们来学习Go语言编程的第五章,函数.首先简单说一下函数的概念和作用.函数是一 ...