线段树区间覆盖 蛤玮打扫教室(zzuli 1877)
http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1877
Description
Input
第一行为一个整数T(1<=T<=20),代表数据组数。每组数据第一行n,m(1<=n,m<=100000),接下来m行,每行两个数L,R(1<=L<=R<=n).
Output
每组数据输出一个k,表示多少个签符合蛤玮的要求,接下来一行输出k个数,这些签的编号,下标从1开始.
Sample Input
Sample Output
#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)的更多相关文章
- NBOJv2 1004 蛤玮打扫教室(线段树区间更新区间最值查询)
Problem 1004: 蛤玮打扫教室 Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit interger IO format: %l ...
- Problem 1004: 蛤玮打扫教室(区间覆盖端点记录)
Problem 1004: 蛤玮打扫教室 Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit interger IO format: %l ...
- HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)
http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...
- [NOI2015] 软件包管理器【树链剖分+线段树区间覆盖】
Online Judge:Luogu-P2146 Label:树链剖分,线段树区间覆盖 题目大意 \(n\)个软件包(编号0~n-1),他们之间的依赖关系用一棵含\(n-1\)条边的树来描述.一共两种 ...
- Mayor's posters POJ - 2528 线段树区间覆盖
//线段树区间覆盖 #include<cstdio> #include<cstring> #include<iostream> #include<algori ...
- POJ - 2528Mayor's posters (离散化+线段树区间覆盖)
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...
- zoj1610线段树区间覆盖
链接https://vjudge.net/contest/66989#problem/F 坑爹的线段树,一直用区间更新做,做了半天一点眉目都没有,只好搜题解,感觉好堕落,经常不会做就搜题解,以后一定要 ...
- POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)
题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...
- HDU1698 Just a Hook(线段树&区间覆盖)题解
Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...
随机推荐
- Dom,pull,Sax解析XML
本篇随笔将详细讲解如何在Android当中解析服务器端传过来的XML数据,这里将会介绍解析xml数据格式的三种方式,分别是DOM.SAX以及PULL. 一.DOM解析XML 我们首先来看看DOM(Do ...
- django os.environ慎用setdefault操作环境变量!
在绝大多数情况下,如果需要在程序运行过程中设置环境变量,使用os.environ.setdefault函数是没有任何问题的,但是有两种场景下setdefault会造成意外的问题,需要慎用: 如果程序执 ...
- 高级数据库技术SQL
- springmvc+mybatis 构建cms+UC浏览器文章功能
最近公司在模拟UC浏览器做一个简单的cms系统,主要针对于企业内部的文章浏览需求,这边考虑用户大多用mobile浏览文章内容,故使用原生的ios和android进行开发,后面也会集成html5. 1. ...
- 大神你好,可以帮我P张图吗?
韩国版的求大神帮我P张图,看得有点下巴脱臼啊!哈哈哈哈哈哈哈~ 感觉照片拍得很尴尬,请大神P得更有动感 拍了跳跃照片,但内衣露出来一点,能帮忙去掉吗 不喜欢没穿制服的样子,请帮忙加上制服 希望背景 ...
- [Robot Framework] 调用ExcelLibrary
安装ExcelLibrary for Robot Framework 参考 : http://navinet.github.io/robotframework-excellibrary/ 打开wind ...
- 解决linux ubuntu不能识别华为手机的问题--升级内核
敝人手中有一个华为mate8,但是debian, ubuntu及一系列衍生版均不能识别.只能识别出一个华为手机助手,但是无法使用华为的内置存贮. 在fedora上是可以完美使用的. 归根到底的原因,是 ...
- js生成简单二维码
js文件下载地址:https://download.csdn.net/download/weixin_38296752/10554485 一.引入qrcode.js文件 <script type ...
- 微信小程序播放视频发送弹幕效果
首先.先来看一下效果图 然后.再看一下官方文档API对video的说明 相关属性解析: danmu-list:弹幕列表 enable-danmu:是否显示弹幕 danmu-btn:弹幕按钮 contr ...
- JAVA钩子方法+模板方法
模板方法: 写一个抽象类,这个抽象类有多个抽象方法,里面设立一个模板方法,这个模板方法也可以称之为模板算法,设立不同方法的执行顺序,封装业务流程,暴露出去: 模板方法模式的特点很好总结,它将一般性的可 ...