线段树区间覆盖 蛤玮打扫教室(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 ...
随机推荐
- Employee类
package demo; import java.time.LocalDate; public class Employee { private String name; private doubl ...
- Oracle_SQL(2) 分组与聚合函数
一.聚合函数1.定义:对表或视图的查询时,针对多行记录只返回一个值的函数.2.用途:用于select语句,HAVING条件二.5种聚合函数1.SUM(n) 对列求和 select sum(sal) f ...
- PYthon end
关键字end可以用于将结果输出到同一行,或者在输出的末尾添加不同的字符. # -*- coding:utf-8 -*- count = 1 while count <=5: i=1 while ...
- Java 7.35 游戏:猜字游戏(C++&Java)
Ps: 有人可能好奇我为什么大费周章的去写主函数,而不直接把所有操作放在类中,Why?类就好比骨干(存放核心的数据和功能),最好提供接口, 避免了类中的输入输出,当然,这也不是绝对的. C++: #i ...
- git分支切换时的时间戳问题
1.为什么git仓库没有保留文件修改时的时间戳? 摘自:https://git.wiki.kernel.org/index.php/Git_FAQ#Why_isn.27t_Git_preservin ...
- POJ3662或洛谷1948 Telephone Lines
二分答案+单源最短路 POJ原题链接 洛谷原题链接 显然可以二分答案,检验\(mid\)可以使用最短路来解决. 将大于\(mid\)的边看成长度为\(1\)的边,说明要使用免费升级服务,否则长度为\( ...
- 采用RedisLive监控Redis服务——安装手册
#1.gcc编译环境确认 .tgz cd Python- ./configure /bin/python2. /usr/bin/python #运行python查看版本 python -V #进行更改 ...
- Servlet会话管理一(URL重写和表单隐藏域)
会话可以简单的理解为客户端用户打开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器的整个过程称为一个会话.即一个客户端用户和服务器端进行通讯的过程,也是客户端和服务器端之间的数据传 ...
- Git/Github的使用并与Eclipse整合(zz)
Git/Github的使用并与Eclipse整合 您的评价: 收藏该经验 Git简介 Git是一个免费的.分布式的版本控制工具,或是一个强调了速度快的源代码管理工具.每一 ...
- Flex的Number和Text
今天要说的问题不是Number和String转换的问题.而是使用时容易出的一些错误: public static function ToFixed(value:Number, digits:uint ...