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. 函数的有用信息,装饰器 day12

    一 函数的有用信息 本函数的功能:绘图功能,实时接收数据并绘图.:return: 绘图需要的数据,返回给前端某标签 def f1(): ''' 本函数的功能:绘图功能,实时接收数据并绘图. :retu ...

  2. Vue 1.0 和 2.0 执行顺序

    // Vue 生命周期 // Vue 1.0 // 执行步骤:选项/生命周期钩子 // 1 init // 2 created // 3 beforeCompile // 4 compiled // ...

  3. Java中的队列都有哪些,有什么区别?

    Queue: 基本上,一个队列就是一个先入先出(FIFO)的数据结构 Queue接口与List.Set同一级别,都是继承了Collection接口.LinkedList实现了Deque接 口. 1.未 ...

  4. iOS.CodeSign

    Inside Code Signing 1. Code Signing需要的基础组件: 证书,私钥 As an iOS developer, chances are you have a certif ...

  5. (O)编写可维护的代码示例(原创)

    图片轮播: /*广告图片数组*/ var imgs=[ {"i":0,"img":"images/index/banner_01.jpg"} ...

  6. SNP命名

    SNP命名 [2016-11-24]       奶茶妹妹是谁,京东老板娘,咦?章泽天!没错! 国民老公是谁?万达少东家,王健林儿子,王思聪!恭喜你又答对了! 函数是谁?这不是数学上的名词吗?不对,是 ...

  7. socket 长连接

    实现: 长连接的维持,是要客户端程序,定时向服务端程序,发送一个维持连接包的. 如果,长时间未发送维持连接包,服务端程序将断开连接. 服务端: 由于客户端会定时(keepAliveDelay毫秒)发送 ...

  8. [ES]elasticsearch章4 ES的META们

    在介绍Meta更新流程前,我们先介绍一下ES中Meta的组成.存储方式和恢复方式. 1. Meta:ClusterState.MetaData.IndexMetaData Meta是用来描述数据的数据 ...

  9. 使用scrollTop返回顶部

    scrollTop属性表示被隐藏在内容区域上方的像素数.元素未滚动时,scrollTop的值为0,如果元素被垂直滚动了,scrollTop的值大于0,且表示元素上方不可见内容的像素宽度 由于scrol ...

  10. strace使用

    统计信息 -c -- count time, calls, and errors for each syscall and report summary 输出结果到文件 -o   例如 strace ...