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 ...
随机推荐
- nios II--实验1——hello_world软件部分
hello_world 软件开发 首先,在硬件工程文件夹里面新建一个software的文件夹用于放置软件部分:打开toolsàNios II 11.0 Software Build Tools for ...
- JavaScript学习笔记-随滚轮匀速滑动的浮动广告窗动画
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- [转]史上最全最强SpringMVC详细示例实战教程
原文:http://www.cnblogs.com/sunniest/p/4555801.html?utm_source=tuicool&utm_medium=referral SpringM ...
- android 使用多个接口
今天,好久没有这么用过都忘记可以这样用了.来记录下: 一个类想要使用多个接口可以implements 接口1 , 接口2,...
- Linux 安装mysql+apache+php
安装mysql 1. yum install mysql mysql-server 2. 修改mysql密码 >use mysql >update user set passwor ...
- Linux系统日志
日 志 文 件 说 明 /var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一 /var/log/secure 与安全相关的日志信息 /va ...
- Android Retrofit网络请求Service,@Path、@Query、@QueryMap、@FieldMap (转)
GET请求 多个参数在URL问号之后,且个数不确定 http://api.stay4it.com/News?newsId=1&type=类型1- http://api.stay4it.com/ ...
- jsp内置对象作业1-用户登录
题目:编写一个jsp程序,实现用户登录,当用户输入的用户名或密码错误时,将页面重定向到错误提示也,并在该页面显示30秒后,自动返回到用户登录页面. 1.用户登录页面 <%@ page langu ...
- python之旅【第二篇】
1,文件操作 找到文件-----打开文件------文件操作-----------文件关闭 file_open = file(文件路径,模式) 读取文件: M.read() obj = M.readl ...
- org.apache.commons.lang3.ArrayUtils 学习笔记
package com.nihaorz.model; /** * @作者 王睿 * @时间 2016-5-17 上午10:05:17 * */ public class Person { privat ...