BZOJ4527: K-D-Sequence 线段树
别人家的题解。
#include<bits/stdc++.h>
#define N 200005
#define M (l+r>>1)
#define P (k<<1)
#define S (k<<1|1)
#define K l,r,k
#define L l,M,P
#define R M+1,r,S
#define Z \
int l=0,int r=n-1,int k=1
using namespace std;
int n,z,d;
typedef int seg[N<<2];
seg s[2],t[2],e;
void apply(int i,int d,Z){
s[i][k]=d;
t[i][k]=d+l;
e[k]=d+t[i^1][k];
}
void devolve(Z){
for(int i=0;i!=2;++i)
if(s[i][k]!=INT_MIN){
apply(i,s[i][k],L);
apply(i,s[i][k],R);
s[i][k]=INT_MIN;
}
}
void update(int k){
for(int i=0;i!=2;++i)
t[i][k]=min(
t[i][P],t[i][S]);
e[k]=min(e[P],e[S]);
}
void change(
int i,int d,int s,int t,Z){
if(s==l&&t==r)
apply(i,d,K);
else{
devolve(K);
if(t<=M)
change(i,d,s,t,L);
else if(s>M)
change(i,d,s,t,R);
else{
change(i,d,s,M,L);
change(i,d,M+1,t,R);
}
update(k);
}
}
int query(int s,int t,Z){
static int d;
return s==l&&t==r
&&e[k]>z?-1:l==r?l
:(devolve(K),
t<=M?query(s,t,L)
:s>M?query(s,t,R)
:~(d=query(s,M,L))
?d:query(M+1,t,R));
}
typedef int ds[N];
ds f,a,q,u,v,p;
typedef pair<int,int> vec;
vec b;
void foo(){
int s=*min_element(a,a+n);
for(int i=0;i!=n;++i)
a[i]-=s;
set<int> t;
for(int i=0,j=0;i!=n;++i){
while(t.count(a[i])
||a[i]%d!=a[j]%d)
t.erase(a[j++]);
f[i]=j;
t.insert(a[i]);
}
for(int i=0,j=0,k=0;
k!=n;++k,++z){
a[u[i+1]=k]/=d;
while(i&&a[p[i]]>a[k])
--i;
p[++i]=v[j+1]=k;
change(0,-a[k],u[i],k);
while(j&&a[q[j]]<a[k])
--j;
q[++j]=k;
change(1,a[k],v[j],k);
int s=query(f[k],k);
b=max(b,vec(k-s+1,-s));
}
}
void bar(){
for(int i=0;i!=n;++i){
int j=i;
while(i+1!=n&&a[i]==a[i+1])
++i;
b=max(b,vec(i-j+1,-j));
}
}
int main(){
scanf("%d%d%d",&n,&z,&d);
for(int i=0;i!=n;++i)
scanf("%d",a+i);
(d?foo:bar)();
printf("%d %d\n",1-b.second,
b.first-b.second);
}
BZOJ4527: K-D-Sequence 线段树的更多相关文章
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- Wow! Such Sequence!(线段树4893)
Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸
D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- hdu4893Wow! Such Sequence! (线段树)
Problem Description Recently, Doge got a funny birthday present from his new friend, Protein Tiger f ...
- HDU 6047 Maximum Sequence(线段树)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...
- Codeforces 438D The Child and Sequence - 线段树
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at ...
- hdu 4893 Wow! Such Sequence!(线段树)
题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...
- hdu-5805 NanoApe Loves Sequence(线段树+概率期望)
题目链接: NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 ...
- Codeforces 486E LIS of Sequence(线段树+LIS)
题目链接:Codeforces 486E LIS of Sequence 题目大意:给定一个数组.如今要确定每一个位置上的数属于哪一种类型. 解题思路:先求出每一个位置选的情况下的最长LIS,由于開始 ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间求和+点修改+区间取模
D. The Child and Sequence At the children's day, the child came to Picks's house, and messed his h ...
随机推荐
- Android之Activity启动模式
正常模式 每个应用都有一个任务栈,任务栈中保存着已创建的Activity,先创建的Activity先入栈,栈顶是当前正在显示的activity(running),这是正常模式下的Activity的管理 ...
- 【原创】解决jquery在ie中不能解析字符串类型xml结构的xml字符串的问题
$.fn.extend({ //此方法解决了ie中jquery不识别非xml的类型的xml字符串的问题 tony tan findX: function (name) { if (this & ...
- URL(待整合到HTTP书中哦)
一:scheme://host.domain:port/path/filename scheme - 定义因特网服务的类型.最常见的类型是 http host - 定义域主机(http 的默认主机是 ...
- 访问修饰符(public,private,protected,internal,sealed,abstract)
为了控件C#中的对象的访问权限,定义对象时可以在前面添加修饰符. 修饰符有五种:private(私有的),protected(受保护的),internal(程序集内部的),public(公开的),以及 ...
- Hibernate正向工程(实体类-->数据库)
1,新建实体类News.java package com.hanqi.dao; import java.util.Date; public class News { private Integer i ...
- word2007插入页码里面不显示或没选项可点怎么办?
1.打开Word 2007 2.单击Microsoft Office按钮 (左上角的圆圈) 3.单击“Word 选项”(在页面的右下方) 4.单击“加载”项(页面左边一排,倒数第三个,出现的页面中,向 ...
- 跨域http请求
<?php header("Access-Control-Allow-Origin: *"); header("Content-Type: application/ ...
- 【收藏】Android更新UI的几种常见方法
----------------将会调用onDraw()重绘控件---------------- 1.view.invalidate刷新UI(主线程) 2.view.postInvalidate刷 ...
- Using the rJava package on Win7 64 bit with R
加载 rJava 包报错: > library(rJava) Error : loadNamespace()里算'rJava'时.onLoad失败了,详细内容: 调用: fun(libname, ...
- Spark 编程基础
1. 初始化Spark import org.apache.spark.{SparkContext, SparkConf} val conf=new SparkConf().setAppName(&q ...