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 ...
随机推荐
- KM模板
var n,m,i,j:longint; ans:int64; sel,lx,ly,slack:..] of int64; a:..,..] of int64; visx,visy:..] of bo ...
- C# 利用反射动态将字符串转换成属性对应的类型值
/// <summary> /// 为指定对象分配参数 /// </summary> /// <typeparam name="T">对象类型& ...
- FileShare枚举的使用(文件读写锁)
开发过程中,我们往往需要大量与文件交互,但往往会出现很多令人措手不及的意外,所以对普通的C#文件操作做了一次总结,问题大部分如下: 1:写入一些内容到某个文件中,在另一个进程/线程/后续操作中要读取文 ...
- Excel——将内容导入
1.写入Excel文件的操作引入Microsoft.Office.Tools.Excel.dll 程序集 List<Person> list = new List<Person> ...
- leetcode-Warm Up Contest-Aug.21
leetcode 地址: https://leetcode.com/contest/detail/1 (1)-- Lexicographical Numbers Given an integer ...
- bindService初步了解
bindService的使用: 当需要调Service里面的方法时,可以用bindService() 首先定义一个类继承于Service,然后配置Manifest.xml文件 public class ...
- Dll的显式和隐式调用
建立项目,请选择Win32 控制台项目(Win32 Console Application),选择DLL和空项目选项.DLLs可能并不如你想像的那样难.首先写你的头文件(header file):称为 ...
- fio 2种画图方法 fio_generate_plots 和 gfio
fio 安装fio apt-get install fio 可以把fio的输出数据自动画图的插件gnuplot apt-get install gnuplot 1.输出bw,lat和iops数据并画图 ...
- T3 任职定级面试准备
山东大学计算机专业本科毕业,工作8年,以前在华为工作,来YY正好1年. 个人心态开放积极,对未知事物好奇心很强,前沿科学.古老宗教皆有涉猎.英语口语能力较强,能和老外流程的交流.技术涉猎广泛,喜好研究 ...
- Ubuntu下安装IDA pro
预备 由于IDA pro只能装在32位环境下,如果是64位Ubuntu,需要运行如下命令安装32位的必备库. sudo dpkg --add-architecture i386 sudo apt-ge ...