5236. 【NOIP2017模拟8.7A组】利普希茨

(File IO): input:lipschitz.in output:lipschitz.out

Time Limits: 1000 ms Memory Limits: 524288 KB Detailed Limits

Description

Input

输入文件名为lipschitz.in。

第一行一个整数n。

接下来一行n个整数,描述序列A。

第三行一个数q 。

接下来q行,每行三个整数。其中第一个整数type表示操作的类型。 type=0对应修改操作, type=1对应查询操作。

Output

输出文件名为lipschitz.out。

对于每个查询,给出f(A[l..r]) 。

Sample Input

输入1:

6

90 50 78 0 96 20

6

0 1 35

1 1 4

0 1 67

0 4 11

0 3 96

1 3 5

输入2:

50

544 944 200 704 400 150 8 964 666 596 850 608 452 103 988 760 370 723 350 862 856 0 724 544 668 891 575 448 16 613 952 745 990 459 740 960 752 194 335 575 525 12 618 80 618 224 240 600 562 283

10

1 6 6

1 1 3

0 11 78279

0 33 42738

0 45 67270

1 1 26

1 19 24

1 37 39

1 8 13

0 7 64428

Sample Output

输出1:

78

85

输出2:

0

744

77683

856

558

77683

Data Constraint

对于30%的数据,n,q<=500

对于60%的数据,n,q<=5000

对于100%的数据,n,q<=100000,0<=ai,val<=10^9

题解

可以转化成坐标

对于每个点(x,y),y表示Ax,先把公式列出来

f(A)=maxi<j⌈|Aj−Ai|j−i⌉

显然,对于任意两点,|Aj−Ai|j−i求出来的就是斜率

因此,只用找到斜率最大的就可以了

对于ABC三点,lAB的斜率比lAC大

对于ABD三点,lBC的斜率比lAD大

所以,在三点中,一定存在相邻的两点最优

因此f(A)=max|Ai+1−Ai|

用线段树维护一下Ai+1−Ai就行了

代码

#include<cstdio>
#include<algorithm>
#define N 100010 struct node{
long maxx;
node *lc,*rc;
}*head;
void init(node* &now)
{
now=new node;
now->maxx=0;
now->lc=now->rc=NULL;
}
void build(long l,long r,node* &now=head)
{
init(now);
if(l!=r){
long mid=(l+r)>>1;
build(l,mid,now->lc);
build(mid+1,r,now->rc);
}
}
void change(long l,long r,long x,long key,node* &now=head)
{
if(l==r)now->maxx=key;
else{
long mid=(l+r)>>1;
if(x<=mid)
change(l,mid,x,key,now->lc);
else
change(mid+1,r,x,key,now->rc);
now->maxx=std::max(now->lc->maxx,now->rc->maxx);
}
}
long query(long l,long r,long x,long y,node *now=head)
{
if(x<=l&&r<=y)return now->maxx;
else{
long mid=(l+r)>>1,maxx=0;
if(x<=mid)
maxx=std::max(maxx,query(l,mid,x,y,now->lc));
if(y>mid)
maxx=std::max(maxx,query(mid+1,r,x,y,now->rc));
return maxx;
}
} long a[N]; int main()
{ long n,m,i,x,y,z;
freopen("lipschitz.in","r",stdin);
freopen("lipschitz.out","w",stdout);
scanf("%ld",&n);
build(1,n);
for(i=1;i<=n;i++){
scanf("%ld",&a[i]);
if(i!=1)
change(1,n,i-1,abs(a[i-1]-a[i]));
}
change(1,n,n,a[n]);
scanf("%ld",&m);
for(i=1;i<=m;i++){
scanf("%ld%ld%ld",&x,&y,&z);
if(!x){
a[y]=z;
change(1,n,y-1,abs(a[y-1]-a[y]));
change(1,n,y,abs(a[y]-a[y+1]));
}else
printf("%ld\n",query(1,n,y,z-1));
}
return 0;
}

JZOJ 5236. 【NOIP2017模拟8.7A组】利普希茨的更多相关文章

  1. JZOJ.5236【NOIP2017模拟8.7】利普希茨

    Description

  2. JZOJ 5235. 【NOIP2017模拟8.7A组】好的排列

    5235. [NOIP2017模拟8.7A组]好的排列 (File IO): input:permutation.in output:permutation.out Time Limits: 1000 ...

  3. [jzoj 5343] [NOIP2017模拟9.3A组] 健美猫 解题报告 (差分)

    题目链接: http://172.16.0.132/senior/#main/show/5343 题目: 题解: 记旋转i次之后的答案为$ans_i$,分别考虑每个元素对ans数组的贡献 若$s_i& ...

  4. JZOJ 5246. 【NOIP2017模拟8.8A组】Trip(trip)

    5246. [NOIP2017模拟8.8A组]Trip(trip) (File IO): input:trip.in output:trip.out Time Limits: 1500 ms Memo ...

  5. JZOJ 3526. 【NOIP2013模拟11.7A组】不等式(solve)

    3526. [NOIP2013模拟11.7A组]不等式(solve) (File IO): input:solve.in output:solve.out Time Limits: 1000 ms M ...

  6. JZOJ 【NOIP2017提高A组模拟9.14】捕老鼠

    JZOJ [NOIP2017提高A组模拟9.14]捕老鼠 题目 Description 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄里的仓库灭灭鼠.于是,猫被农夫约派去捕 ...

  7. JZOJ 5230. 【NOIP2017模拟A组模拟8.5】队伍统计

    5230. [NOIP2017模拟A组模拟8.5]队伍统计 (File IO): input:count.in output:count.out Time Limits: 1500 ms Memory ...

  8. JZOJ 4273. 【NOIP2015模拟10.28B组】圣章-精灵使的魔法语

    4273. [NOIP2015模拟10.28B组]圣章-精灵使的魔法语 (File IO): input:elf.in output:elf.out Time Limits: 1000 ms  Mem ...

  9. JZOJ 3509. 【NOIP2013模拟11.5B组】倒霉的小C

    3509. [NOIP2013模拟11.5B组]倒霉的小C(beats) (File IO): input:beats.in output:beats.out Time Limits: 1000 ms ...

随机推荐

  1. linux压缩管理系统

    Linux压缩管理系统windows        rar       zipLinux       zip        tar.gz       tar.bz2       tar.xz 压缩的好 ...

  2. 依据gff切fa并翻译为蛋白质

    #!/usr/bin/python import re import sys import gzip change={'A':'T','T':'A','C':'G','G':'C','N':'N'} ...

  3. git 首次提交

    git init# 将本地仓库与码云远程仓库进行关联 git remote add origin git的url地址 git add . git commit -m "描述" # ...

  4. Ubuntu navicat 连接mysql:access denied for user 'root'@'localhost'

    真是醉了,Ubuntu装了navicat后,准备在桌面建立图标不成,结果直接打开后连接mysql都不行,真坑,奈何远程连接就成,这就尬了,今天终于解决了 问题 我也百度了好几个方案,奈何解决不了,最后 ...

  5. Python的range(n)的用法

    Python的range(n) 方法就是: API定义: If you do need to iterate(迭代) over a sequence(一系列) of numbers, the buil ...

  6. java课java方法动手动脑

    动手动脑: import java.util.Scanner; public class Random { public static void main(String[] args) {       ...

  7. 多版本firefox共存

    https://blog.csdn.net/gavinxlf/article/details/53173034 https://blog.csdn.net/weixin_33979745/articl ...

  8. LeetCode Day 10

    LeetCode0020 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序 ...

  9. 为什么说iPhone无望恢复中国市场?

    直到现在还记得,iPhone 4在国内当时引发的追捧狂潮.彼时iPhone 4绝对是一机难求,上至土豪下至学生都以拥有iPhone 4为荣.发售接近一年后仍然需要加价,价格动辄达到七八千元,真正成为了 ...

  10. LG_3459_[POI2007]MEG-Megalopolis

    题目描述 Byteotia has been eventually touched by globalisation, and so has Byteasar the Postman, who onc ...