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 ...
随机推荐
- 史密斯(smith)圆图讲解
不管多么经典的射频教程,为什么都做成黑白的呢?让想理解史密斯原图的同学一脸懵逼. 这是什么东东? 今天解答三个问题: 1.是什么? 2.为什么? 3.干什么? 1.是什么? 该图表是由菲利普·史密斯( ...
- JavaScript学习笔记-随滚轮匀速滑动的浮动广告窗动画
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- 检测IE浏览器方法
var isIE=function(){ var b=document.createElement("b"); b.innerHTML="<!--[if IE]&g ...
- Go加密解密之DES
一.DES简介 DES(Data Encryption Standard)是对称加密算法,也就是加密和解密用相同的密钥.其入口参数有三个:key.data.mode.key为加密解密使用的密钥,dat ...
- iOS-- 重要的链接
面试题: http://www.jianshu.com/p/6a57c6e902e8 富文本: http://www.cnblogs.com/jys509/p/5018027.html
- fatal: Not a valid object name: 'master'.
fatal: Not a valid object name: 'master'. the answer is : That is again correct behaviour. Until you ...
- 【POJ 2406】Power Strings 连续重复子串
看的<后缀数组——处理字符串的有力工具>这篇论文,在那里这道题是用后缀数组实现的,复杂度为$O(nlogn)$,很明显长度为$2×10^6$的数据会TLE,所以必需得用复杂度为$O(n)$ ...
- 【转载】java版打字练习软件
网上找到一个java版的打字的游戏 import java.applet.Applet; import java.applet.AudioClip; import java.awt.Dimension ...
- hdu4725最短路变形 添加点
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- Activiti 学习笔记记录(2016-8-31)
上一篇:Activiti 学习笔记记录(二) 导读:上一篇学习了bpmn 画图的常用图形标记.那如何用它们组成一个可用文件呢? 我们知道 bpmn 其实是一个xml 文件