别人家的题解。

#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 线段树的更多相关文章

  1. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  2. Wow! Such Sequence!(线段树4893)

    Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...

  3. 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 ...

  4. hdu4893Wow! Such Sequence! (线段树)

    Problem Description Recently, Doge got a funny birthday present from his new friend, Protein Tiger f ...

  5. HDU 6047 Maximum Sequence(线段树)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...

  6. 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 ...

  7. 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区间上的所以数变成 ...

  8. hdu-5805 NanoApe Loves Sequence(线段树+概率期望)

    题目链接: NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 262144/131072 ...

  9. Codeforces 486E LIS of Sequence(线段树+LIS)

    题目链接:Codeforces 486E LIS of Sequence 题目大意:给定一个数组.如今要确定每一个位置上的数属于哪一种类型. 解题思路:先求出每一个位置选的情况下的最长LIS,由于開始 ...

  10. 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 ...

随机推荐

  1. 数学符号“s.t.”的意义

    在优化问题的求解中,如线性规划.非线性规划问题等,经常会遇到数学符号“s.t.”,它的意思是什么呢? “s.t.”,指 subject to,受限制于.... 例如: 目标函数:min {x+2} 约 ...

  2. learning to rank

    Learning to Rank入门小结 + 漫谈 Learning to Rank入门小结 Table of Contents 1 前言 2 LTR流程 3 训练数据的获取4 特征抽取 3.1 人工 ...

  3. SqlServer——全文索引

    当我们想要模糊查询时,之前用like %来进行查询,但是为了提高查询速度,提出了全文索引. 全文索引是用空间换取了时间,它将每个表中的数据进行切分存储,这样就能很快的定位到模糊查询的数据. 全文索引快 ...

  4. Tomcat6查看数据库的数据源信息

    打开tomcat6\conf  下的 context.xml

  5. 用CSS和jQuery制作简单的下拉框

    请选择 百度 谷歌 雅虎 新浪 dowebok 代码 素材 模板 教程 示例下载 // li', function() { var parent = $(this).closest('.select' ...

  6. 3.python算法之完全数

    代码: #!/usr/bin/env python # encoding: utf-8 """ @author: 侠之大者kamil @file: 3.完全数.py @t ...

  7. 【BZOJ-1009】GT考试 KMP+DP+矩阵乘法+快速幂

    1009: [HNOI2008]GT考试 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2745  Solved: 1694[Submit][Statu ...

  8. 【bzoj1912】 Apio2010—patrol 巡逻

    http://www.lydsy.com/JudgeOnline/problem.php?id=1912 (题目链接) 题意 给出一棵树,要求在树上添加K(1 or 2)条边,添加的边必须经过一次,使 ...

  9. 【poj2960】 S-Nim

    http://poj.org/problem?id=2960 (题目链接) 题意 经典Nim游戏,只是给出了一个集合S,每次只能取S[i]个石子. Solution ${g(x)=mex\{SG(x- ...

  10. wpf添加超链接

    前段: <TextBlock Margin="69,93,859,10"> <Hyperlink NavigateUri="http://dmsite. ...