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. 64位Win7系统下vs2010调试无法连接oracle解决办法

    具体的解决办法如下: 1.先将WebDev.WebServer20.EXE和WebDev.WebServer40.EXE文件从Program Files (x86)目录中拷贝出来放到c:\dev目录中 ...

  2. Android——Activity跳转

    Activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayou ...

  3. gdal source code c++ make windows

    下载源码 GDAL源代码下载地址:http://trac.osgeo.org/gdal/wiki/DownloadSource,或者安装svn从源代码服务器下载,svn地址是:http://svn.o ...

  4. LibreOJ #6002. 「网络流 24 题」最小路径覆盖

    #6002. 「网络流 24 题」最小路径覆盖 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:Special Judge 上传者: 匿名 提交提交记录统计讨论测 ...

  5. POJ 3469.Dual Core CPU 最大流dinic算法模板

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 24830   Accepted: 10756 ...

  6. 开发中,android手机WIFI无法使用,无SIM卡故障解决

    用eclipse 开发android中,突然出现,android手机WIFI无法使用,无SIM卡故障解决 发现故障后,想办法刷机(没有成功),触点清洁都搞了. 最后恢复出厂设置居然解决了,留资料给同行 ...

  7. Autofs

    1. Introduction autofs is a program for automatically mounting directories on an as-needed basis. Au ...

  8. [Jmeter] Concurrency Thread Group

    Concurrency Thread Group : https://jmeter-plugins.org/wiki/ConcurrencyThreadGroup/ 参数介绍: Target Conc ...

  9. 买茶叶想到的哪个比较便宜 x1/y1 >x2/y2 x代表多少钱 y代表 多少克 无聊的试炼

    茶叶1 128元     200克 茶叶2  330元    160克 当然这个哪个便宜 一眼就知道了,这里不过抛砖引玉 128元    330元 200克    160克 我们把价钱用x表示 多少克 ...

  10. spring boot 启动自动跳到 断点 throw new SilentExitException

    项目 debug 启动,自动跳到 断点 ,而且就算F8 ,项目还是停止启动. 百度了一下,答案都是 Eclipse -> Preferences ->Java ->Debug去掉&q ...