http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1877

Description

 
现在知道一共有n个机房,算上蛤玮一共有m个队员,教练做了m个签,每个签上写着两个数L,R(L<=R),抽到的人要把[L,R]的教室全部打扫一遍.由于蛤玮是队长而且他很懒,他通过某种交易提前知道了所有m个签上面写的是什么,而且通过某种魔法可以控制自己抽到哪个签.一个教室被打扫一次就干净了,所以蛤玮想知道自己抽哪些签可以不用打扫教室而且不会被教练发现,即他抽到的区间全都会被别人打扫一遍.
 
蛤玮被教练叫去打扫机房,集训队有很多机房,也有很多队员,现在他们要用抽签的方式决定谁打扫哪间教室.

Input

第一行为一个整数T(1<=T<=20),代表数据组数。每组数据第一行n,m(1<=n,m<=100000),接下来m行,每行两个数L,R(1<=L<=R<=n).

Output

每组数据输出一个k,表示多少个签符合蛤玮的要求,接下来一行输出k个数,这些签的编号,下标从1开始.

Sample Input

3 15 5 1 4 5 5 6 8 9 10 5 6 3 6 1 1 1 1 2 2 2 2 3 3 3 3 10 3 1 4 2 6 6 10

Sample Output

2 2 5 6 1 2 3 4 5 6 0
 
2016轻院校赛失之交臂的题呀!!!
 
 
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
using namespace std; #define EPS 1e-6
#define N 110000
#define met(a,b) (memset(a,b,sizeof(a)))
#define Lson r<<1
#define Rson r<<1|1 struct E
{
int L, R;
}a[N]; int v[N]; struct node
{
int L, R, x;
int mid()
{
return (L+R)/;
}
int len()
{
return (R-L+);
}
}Tree[N<<]; void BuildTree(int r, int L, int R)
{
Tree[r].L = L, Tree[r].R = R, Tree[r].x = ; if(L==R)
return ; BuildTree(Lson, L, Tree[r].mid());
BuildTree(Rson, Tree[r].mid()+, R);
} void Update(int r, int L, int R)
{
if(Tree[r].L==L && Tree[r].R==R)
{
Tree[r].x++;
return ;
} if(R<=Tree[r].mid())
Update(Lson, L, R);
else if(L>Tree[r].mid())
Update(Rson, L, R);
else
{
Update(Lson, L, Tree[r].mid());
Update(Rson, Tree[r].mid()+, R);
}
} void Up(int r, int L, int R)
{
if(L==R)
return ; Tree[Lson].x += Tree[r].x;
Tree[Rson].x += Tree[r].x; Up(Lson, L, Tree[r].mid());
Up(Rson, Tree[r].mid()+, R); Tree[r].x = min(Tree[Lson].x, Tree[Rson].x);
} int Query(int r, int L, int R)
{
if(Tree[r].L==L && Tree[r].R==R)
return Tree[r].x; if(R<=Tree[r].mid())
return Query(Lson, L, R);
else if(L>Tree[r].mid())
return Query(Rson, L, R);
else
return min(Query(Lson, L, Tree[r].mid()), Query(Rson, Tree[r].mid()+, R));
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int n, m, i, k=, ans; scanf("%d%d", &n, &m); met(a,);
met(v,);
BuildTree(, , n); for(i=; i<=m; i++)
{
scanf("%d%d", &a[i].L, &a[i].R);
Update(, a[i].L, a[i].R);
} Up(, , n); for(i=; i<=m; i++)
{
ans = Query(, a[i].L, a[i].R);
if(ans>=)
v[k++] = i;
} printf("%d\n", k);
for(i=; i<k; i++)
printf("%d%c", v[i], i==k-?'\n':' '); }
return ;
}
 关于区间覆盖很巧妙地一种用法, 跟之前写的有个涂气球的有个题, 思想是相同的, 这次记下, 以后定有用处

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
using namespace std; #define EPS 1e-6
#define N 110000
#define met(a,b) (memset(a,b,sizeof(a))) struct node
{
int L, R;
}a[N]; int v[N], w[N], sum[N], b[N]; int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int n, m, i, s=, k=; scanf("%d%d", &n, &m);
met(v, );
met(sum, );
met(w, );
met(b, ); for(i=; i<=m; i++)
{
scanf("%d%d", &a[i].L, &a[i].R);
v[a[i].L]++;
v[a[i].R+]--;
} for(i=; i<=n; i++)
{
s += v[i];
w[i] = s;
} for(i=; i<=n; i++)
{
if(w[i]>=) sum[i] = sum[i-]+;
else sum[i] = sum[i-];
} for(i=; i<=m; i++)
{
if(sum[a[i].R]-sum[a[i].L-]==a[i].R-a[i].L+)
b[k++] = i;
} printf("%d\n", k);
for(i=; i<k; i++)
printf("%d%c", b[i], i==k-?'\n':' ');
}
return ;
}

线段树区间覆盖 蛤玮打扫教室(zzuli 1877)的更多相关文章

  1. NBOJv2 1004 蛤玮打扫教室(线段树区间更新区间最值查询)

    Problem 1004: 蛤玮打扫教室 Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit interger IO format:  %l ...

  2. Problem 1004: 蛤玮打扫教室(区间覆盖端点记录)

    Problem 1004: 蛤玮打扫教室 Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit interger IO format:  %l ...

  3. HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)

    http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...

  4. [NOI2015] 软件包管理器【树链剖分+线段树区间覆盖】

    Online Judge:Luogu-P2146 Label:树链剖分,线段树区间覆盖 题目大意 \(n\)个软件包(编号0~n-1),他们之间的依赖关系用一棵含\(n-1\)条边的树来描述.一共两种 ...

  5. Mayor's posters POJ - 2528 线段树区间覆盖

    //线段树区间覆盖 #include<cstdio> #include<cstring> #include<iostream> #include<algori ...

  6. POJ - 2528Mayor's posters (离散化+线段树区间覆盖)

    The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...

  7. zoj1610线段树区间覆盖

    链接https://vjudge.net/contest/66989#problem/F 坑爹的线段树,一直用区间更新做,做了半天一点眉目都没有,只好搜题解,感觉好堕落,经常不会做就搜题解,以后一定要 ...

  8. POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)

    题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...

  9. HDU1698 Just a Hook(线段树&区间覆盖)题解

    Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...

随机推荐

  1. 一个命令查看mysql的所有配置(原创)

    在mysql的命令提示符下,执行下面一句话,查看mysql服务器的所有全局配置信息: mysql> show global variables; 得到: 上表的文本内容: "Varia ...

  2. Oracle性能优化3-sql优化一定要等价

    做sql优化的前提瞧见是sql等价 1.MAX MIN写法的分与合 drop table t purge; create table t as select * from dba_objects; a ...

  3. vs 调试 IE显示“无法显示该网页

    在用VS2010调试网站的时候,突然页面不能正常显示了,IE显示“无法显示该网页”.症状一: IE地址栏里面显示的端口号和桌面任务栏右下角“ASP.NET Development Server”的端口 ...

  4. 在IP网络中,P、PE、CE代表意思

    1.ce , pe属于mpls vpn里的概念.VPN概念中,把整个网络中的路由器分为三类:用户边缘路由器(CE).运营商边缘路由器(PE)和运营商骨干路由器(P):其中,PE充当IP VPN接入路由 ...

  5. 大数java(pow)

    Problems involving the computation of exact values of very large magnitude and precision are common. ...

  6. [转载] Linux中的搜索文件命令

    搜索文件用处很大,我们往往需要知道一个文件存放在什么地方,我们又知道Linux是命令强大的一个系统,所以也有好多非常优秀的搜索命令.通常find不常用,因为速度慢,耗费硬盘空间.通常我们先使用wher ...

  7. spring自动注解Autowired配置

    1.spring注解:http://blog.csdn.net/xyh820/article/details/7303330/ 2.最简ssm配置:http://blog.csdn.net/qq_18 ...

  8. linux 常用命令(三)ssh

    linux 常用命令(三)SSH 一.SSH 安装及免密登陆 (1) SSH 安装并配置 CentOS 默认已安装了 SSH client.SSH server,打开终端执行如下命令进行检验 rpm ...

  9. Python之路(第二十二篇) 面向对象初级:概念、类属性

    一.面向对象概念 1. "面向对象(OOP)"是什么? 简单点说,“面向对象”是一种编程范式,而编程范式是按照不同的编程特点总结出来的编程方式.俗话说,条条大路通罗马,也就说我们使 ...

  10. servlet 高级知识之Listener

    Listener,顾名思义,监听器.它可以监听客户端的请求.服务端的操作等. 通过监听器,可以自动激发一些操作,比如监听在线的用户的数量.当增加一个HttpSession时,就激发sessionCre ...