北大zhw大神bzoj1756代码
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
int tree[][],a[],n,m,A,B,C,i,ans,t,x;
void Update(int x)
{
tree[x][]=tree[x*][]+tree[x*+][];
tree[x][]=max(tree[x*][],tree[x*+][]);
tree[x][]=max(tree[x*][],tree[x*][]+tree[x*+][]);
tree[x][]=max(tree[x*+][],tree[x*+][]+tree[x*][]);
tree[x][]=max(max(tree[x*][],tree[x*+][]),tree[x*][]+tree[x*+][]);
}
int WORK(int root,int l,int r)
{
if (tree[root][]==l && tree[root][]==r) return tree[root][];
int mid=(tree[root][]+tree[root][])/,p=-,q=-;
if (l<=mid) p=WORK(root*,l,min(mid,r));
if (r>mid) q=WORK(root*+,max(l,mid+),r);
return max(p,q);
}
void work(int root,int l,int r)
{
if (tree[root][]==l && tree[root][]==r)
{
ans=max(ans,tree[root][]+t);
ans=max(ans,tree[root][]);
t=max(t+tree[root][],tree[root][]);
t=max(t,);
return;
}
int mid=(tree[root][]+tree[root][])/;
if (l<=mid) work(root*,l,min(mid,r));
if (r>mid) work(root*+,max(mid+,l),r);
}
int main()
{
scanf("%d%d",&n,&m);
for (i=; i<=n; i++) scanf("%d",&a[i]);
for (i=; i<=; i++)
{
tree[i][]=tree[i][]=i;
tree[i][]=tree[i][]=a[i-];
tree[i][]=tree[i][]=tree[i][]=max(a[i-],);
}
for (i=; i>=; i--)
{
tree[i][]=tree[i*][];
tree[i][]=tree[i*+][];
Update(i);
}
for (i=; i<=m; i++)
{
scanf("%d%d%d",&A,&B,&C);
if (A==)
{
x=+B;
tree[x][]=tree[x][]=C;
tree[x][]=tree[x][]=tree[x][]=max(C,);
while (x!=)
{
x/=;
Update(x);
}
}
else
{
if (B>C) swap(B,C);
t=;
ans=WORK(,B+,C+);
if (ans<) printf("%d\n",ans); else
{
work(,B+,C+);
printf("%d\n",ans);
}
}
}
return ;
}
北大zhw大神bzoj1756代码的更多相关文章
- 为何你跟着滴滴D8级前端大神撸代码,技术却依旧原地踏步?
引子 听说最近有很多小伙伴,热衷于在慕课网上学习各种前端实战教程,并以完成项目为奋斗目标.比如本文接下来要提到的<Vue2.0高级实战之开发移动端音乐App>,这门课程的传授者是来自滴滴D ...
- kaggle新手如何在平台学习大神的代码
原创:数据臭皮匠 [导读]Kaggle ,作为听说它很牛X但从未接触过的同学,可能仅仅了解这是一个参加数据挖掘比赛的网站,殊不知Kaggle也会有赛题相关的数据集, 比如我们熟知的房价预测.泰坦尼克 ...
- zhw大神线段树姿势
; i<; i++) tree[i][]=tree[i][]=i; ; i>=; i--) tree[i][]=tree[i+i][], tree[i][]=tree[i+i+][]; v ...
- PAT1080 MOOC期终成绩 (25分) ——同样参考了柳婼大神的代码及思路,在自己的代码上做了修改,还是很复杂
1080 MOOC期终成绩 (25分) 对于在中国大学MOOC(http://www.icourse163.org/ )学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分 ...
- 【leetcode】Wildcard Matching(hard) ★ 大神太牛了
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- 老猪带你玩转自定义控件三——sai大神带我实现ios 8 时间滚轮控件
ios 8 的时间滚轮控件实现了扁平化,带来很好用户体验,android没有现成控件,小弟不才,数学与算法知识不过关,顾十分苦恼,幸好在github上找到sai大神实现代码,甚为欣喜,顾把学习这个控件 ...
- 解迷宫的C++的未完善编程代码........请大神们帮忙改善下.........
这...................................................................... 我也是醉了 看不太懂,大神们求解............ ...
- ruby大神与菜鸟的代码区别
之前Brand类 has_and_belongs_to_many :categories, index: true 现在在Category类 增加 has_and_belongs_to_many ...
- 【python】抄写大神的糗事百科代码
照着静觅大神的博客学习,原文在这:http://cuiqingcai.com/990.html 划重点: 1. str.strip() strip函数会把字符串的前后多余的空白字符去掉 2. resp ...
随机推荐
- Javascript 原型链与constructor
Javascript中的constructor与prototype 在学习javascript面向对象编程的过程中, constructor和prototype一直让我觉得理解不透,慢慢的学习过程中记 ...
- mysql5.7报Access denied for xxx@localhost 的解决
使用root用户登录mysql数据库若如下报错 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor ...
- buf.write()
buf.write(string[, offset[, length]][, encoding]) string {String} 需要被写入到 Buffer 的字节 offset {Number} ...
- The Falling Leaves(建树方法)
uva 699 紫书P159 Each year, fall in the North Central region is accompanied by the brilliant colors of ...
- empty array & Array.from
empty array bug const duplicationArray = (arr = [], times = 2, debug = false) => { let result = [ ...
- apt-get使用指南
最近频繁使用apt-cache show(查看软件包详细信息)与apt-cache search(搜寻具体软件包确切名称)命令,深感方便与功能强大.现将一些apt-get相关命令做一个简单的收集: a ...
- Drools介绍与使用
Drools 是用 Java 语言编写的开放源码规则引擎,使用 Rete 算法对所编写的规则求值.Drools 允许使用声明方式表达业务逻辑.可以使用非 XML 的本地语言编写规则,从而便于学习和理解 ...
- [bzoj1582][Usaco2009 Hol]Holiday Painting 节日画画_线段树
Holiday Painting 节日画画 bzoj-1582 Usaco-2009 Hol 题目大意:给定两个n*m的01网格图.q次操作,每次将第二个网格图的子矩阵全部变成0或1,问每一次操作后两 ...
- [bzoj 2463]谁能赢呢?(博弈论)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2463 分析:因为都是按最优策略,所以棋盘肯定都能走满,于是胜负关系就是判断n*n的奇偶 ...
- W3School Memcached教程(安装/基本操作/高级操作/命令)
来自W3School的Memcached教程,基本上涵盖了从安装到状态监控的教程. 不过最全的应该是官方提供在GitHub上的Wiki教程,一切的标准都来自官方,参考:https://github.c ...