bzoj4059
题解:
还是一道不错的题目
首先它要求每个区间都满足要求,所以我们很容易想到将它映射到二维平面上
然后我们算出每个数的前驱以及后继li,ri
那么第一维是li-i,第二维是i-ri的区间就是合法的,同理交换
这样就变成了矩形覆盖问题
然后因为是不能遍历所有点的所以二维差分是不行的
2种方法
1.线段树+扫描线,将矩形两条边变为一条插入一条删除 nlogn
2.二维线段树 nlog^2n
另外正解其实也是很好想的
我们注意到如果有一个元素在整个序列中只出现了一次,序列就被分割为两个了
所以我们只要从两边一起向中间寻找就可以了
为什么这个复杂度是对的?
因为它是启发式合并的逆过程,每次分裂的复杂度是较小的那个
*不太想写正解没什么意思。。
代码:
*把清空操作变成vector记录就能过了我懒得改了
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rint register int
#define rep(i,h,t) for (rint i=h;i<=t;i++)
#define dep(i,t,h) for (rint i=t;i>=h;i--)
#define mid ((h+t)/2)
#define me(x) memset(x,0,sizeof(x))
char ss[<<],*A=ss,*B=ss;
char gc()
{
return A==B&&(B=(A=ss)+fread(ss,,<<,stdin),A==B)?EOF:*A++;
}
template<class T> void read(T &x)
{
rint f=,c; while (c=gc(),c<||c>) if (c=='-') f=-; x=c^;
while (c=gc(),c>&&c<) x=(x<<)+(x<<)+(c^); x*=f;
}
const int N=3e5;
int n,m,pre[N],scc[N],data[N*],x[N];
map<int,int>pos;
bool v[N*];
struct re{
int a,b,c,d;
}a[N*];
bool cmp(re x,re y)
{
return (x.a<y.a||((x.a==y.a)&&x.d>y.d));
}
void updata(int x)
{
if (data[x]>||(v[x*]&&v[x*+])) v[x]=; else v[x]=;
}
void insert(int x,int h,int t,int h1,int t1,int pos)
{
if (h1<=h&&t<=t1)
{
data[x]+=pos;
updata(x); return;
}
if (h1<=mid) insert(x*,h,mid,h1,t1,pos);
if (t1>mid) insert(x*+,mid+,t,h1,t1,pos);
updata(x);
}
int main()
{
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
int T;
read(T);
rep(tt,,T)
{
read(n);
pos.clear();
me(pre); me(scc); me(data); me(v);
rep(i,,n)
{
read(x[i]);
pre[i]=pos[x[i]]+;
if (pos[x[i]]) scc[pos[x[i]]]=i-;
pos[x[i]]=i;
}
rep(i,,n)
{
if (!pre[i]) pre[i]=;
if (!scc[i]) scc[i]=n;
}
rep(i,,n)
{
a[i*-].a=pre[i]; a[i*-].b=i; a[i*-].c=scc[i]; a[i*-].d=;
a[i*-].a=i+; a[i*-].b=i; a[i*-].c=scc[i]; a[i*-].d=-;
a[i*-].a=i; a[i*-].b=pre[i]; a[i*-].c=i; a[i*-].d=;
a[i*].a=scc[i]+; a[i*].b=pre[i]; a[i*].c=i; a[i*].d=-;
}
int m=n;
n=*n;
sort(a+,a+n+,cmp);
bool t=;
// for (int i=1;i<=n;i++)
// cout<<a[i].a<<" "<<a[i].b<<" "<<a[i].c<<" "<<a[i].d<<endl;
rep(i,,n)
{
if (a[i].a>m) break;
insert(,,m,a[i].b,a[i].c,a[i].d);
if (a[i+].a!=a[i].a&&!v[])
{
t=; printf("boring\n");
break;
}
}
if (t) printf("non-boring\n");
}
return ;
}
bzoj4059的更多相关文章
- bzoj4059 [Cerc2012]Non-boring sequences && bzoj5200 [NWERC2017]Factor-Free Tree
https://konnyakuxzy.github.io/BZPRO/JudgeOnline/4059.html https://cn.vjudge.net/problem/Gym-100624D ...
- 【BZOJ4059】Non-boring sequences(分析时间复杂度)
题目: BZOJ4059 分析: 想了半天没什么想法,百度到一个神仙做法-- 设原数列为 \(a\),对于每一个 \(i\) 求出前一个和后一个和 \(a_i\) 相等的位置 \(pre[i]\) 和 ...
- 【BZOJ-4059】Non-boring sequences 线段树 + 扫描线 (正解暴力)
4059: [Cerc2012]Non-boring sequences Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 440 Solved: 16 ...
- 【BZOJ4059】Non-boring sequences
Solution 记序列为\(a\),计算出与\(a_i\)相等的前一个元素的位置\(pre_i\),以及后一个元素的位置\(nex_i\),显然,对于那些左端点处于\((pre_i,i]\)以及右端 ...
- bzoj4059 [Cerc2012]Non-boring sequences
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4059 [题解] 考虑分治.定义过程solve(l,r)为判断全在[l,r]范围内的所有连续子 ...
- 【bzoj4059】[Cerc2012]Non-boring sequences 分治
题目描述 我们害怕把这道题题面搞得太无聊了,所以我们决定让这题超短.一个序列被称为是不无聊的,仅当它的每个连续子序列存在一个独一无二的数字,即每个子序列里至少存在一个数字只出现一次.给定一个整数序列, ...
- 【启发式拆分】bzoj4059: [Cerc2012]Non-boring sequences
这个做法名字是从武爷爷那里看到的…… Description 我们害怕把这道题题面搞得太无聊了,所以我们决定让这题超短.一个序列被称为是不无聊的,仅当它的每个连续子序列存在一个独一无二的数字,即每个子 ...
- BZOJ4059[Cerc2012]Non-boring sequences(扫描线/分治)
这题正解应该是扫描线,就是发现DP的区间在两个维度都为连续段,于是可以直接扫描线.但不幸的是,扫描线常数过大,无法通过本题. 考虑分治.对于分治区间[l,r],可以记录pre和nxt表示其前/后一次出 ...
- 【启发式拆分】bzoj5200: [NWERC2017]Factor-Free Tree
和bzoj4059: [Cerc2012]Non-boring sequences非常相似 Description 一棵Factor-Free Tree是指一棵有根二叉树,每个点包含一个正整数权值,且 ...
随机推荐
- (转!)Pyinstaller 打包发布经验总结
原文地址 https://blog.csdn.net/weixin_42052836/article/details/82315118 具体的实现图待本人实现后贴上 原 Pyinstaller 打包发 ...
- 030_CORS深究
在日常的项目开发时会不可避免的需要进行跨域操作,而在实际进行跨域请求时,经常会遇到类似 No 'Access-Control-Allow-Origin' header is present on th ...
- C# 获取区域和语言值
其他方法如 System.Globalization.CultureInfo.InstalledUICulture.Name == "zh-CN" 不能获取.只有通过读注册表的方法 ...
- MS SQL Server 增删改查
数据插入 语法:INSERT INTO Table_name(field1,field2……fieldN) values(value1,vlaue2,…valueN) 单行插入用户类型 INSERT ...
- JsonResponse
1.JsonResponse class JsonResponse(data, encoder=DjangoJSONEncoder, safe=True, json_dumps_params=None ...
- table中border-collapse的问题
在table中,如果设置了border-collapse: collapse;,边框会合并,这时你修改top或bottom的颜色,会有问题 解决办法是:border-collapse: separat ...
- Oracle 口令文件:即 oracle密码文件
一:文件路径位置 [oracle@localhost db_1]$ cd $ORACLE_HOME/dbs [oracle@localhost dbs]$ ls dbsorapwPROD1 hc_or ...
- Flask框架(一)
Flask框架 Flask本身想当于一个内核,其自身几乎所有功能都依靠扩展(邮件扩展Flask-Mail.用户认证Flask-Login),都需要用第三方的扩展来实现.其WSGI工具箱采用Werkze ...
- Selenium WebDriver中鼠标事件
鼠标点击操作 鼠标点击事件有以下几种类型: 清单 1. 鼠标左键点击 Actions action = new Actions(driver);action.click();// 鼠标左键在当 ...
- SpringBoot全局日志管理(AOP)
1.在pom.xml中引入aop的jar包 <dependency> <groupId>org.springframework.boot</groupId> < ...